Blame |
Last modification |
View Log
| RSS feed
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using System.Drawing;
using System.ComponentModel;
using System.ComponentModel.Design;
using BauzoidNET.math;
namespace BauzoidNET
.controls
{
public class RadioToolButton
: RadioButton
{
private int mOffset
= 3;
private bool mIsHovering
= false;
public RadioToolButton
()
: base()
{
this.Appearance = Appearance
.Button;
this.Font = new Font
(Font
.FontFamily, 6
.5f, Font
.Style);
this.AutoSize = false;
}
protected override void OnPaint
(PaintEventArgs e
)
{
Rectangle clientRect
= new Rectangle
(0,
0, ClientRectangle
.Width - 1, ClientRectangle
.Height - 1);
Graphics g
= e
.Graphics;
ButtonRenderer
.DrawParentBackground(g, e
.ClipRectangle,
this);
if (this.Appearance == System.Windows.Forms.Appearance.Button)
{
// Background
if (this.Checked)
{
byte red
= (byte)MathUtil
.clamp((SystemColors
.Highlight.R + SystemColors
.ButtonFace.R)/2,
0,
255);
byte green
= (byte)MathUtil
.clamp((SystemColors
.Highlight.G + SystemColors
.ButtonFace.G) / 2,
0,
255);
byte blue
= (byte)MathUtil
.clamp((SystemColors
.Highlight.B + SystemColors
.ButtonFace.B) / 2,
0,
255);
Color c
= Color
.FromArgb(red, green, blue
);
g
.FillRectangle(new SolidBrush
(c
), e
.ClipRectangle);
}
else
{
//g.FillRectangle(new SolidBrush(Color.Blue), e.ClipRectangle);
}
// Image
if (this.Image != null)
{
Rectangle r
= new Rectangle
((clientRect
.Width - this.Image.Width - mOffset
),
(clientRect
.Height - this.Image.Height - mOffset
),
this.Image.Width,
this.Image.Height);
/*if (this.Checked)
r.Offset(1, 1);*/
g
.DrawImage(this.Image, r
);
}
if (this.Text != "")
{
g
.DrawString(this.Text, Font, SystemBrushes
.ActiveCaptionText, mOffset, mOffset
);
}
// Outline
if (this.Checked || mIsHovering
)
{
g
.DrawRectangle(new Pen
(SystemColors
.Highlight,
1), clientRect
);
}
else
{
g
.DrawRectangle(new Pen
(Color
.Black,
1), clientRect
);
}
}
else
{
base.OnPaint(e
);
}
}
protected override void OnMouseEnter
(EventArgs eventargs
)
{
mIsHovering
= true;
base.OnMouseEnter(eventargs
);
}
protected override void OnMouseLeave
(EventArgs eventargs
)
{
mIsHovering
= false;
base.OnMouseLeave(eventargs
);
}
[Description
("Offset of Text/Image into Button"), Category
("Appearance")]
public int Offset
{
get
{ return mOffset
; }
set
{
mOffset
= value
;
Invalidate
();
}
}
}
}