GDI +를 사용하여 단추를 그리는 사용자 지정 UserControl을 만들었습니다. 그것은 "빛깔"같은 것이 아니지만 외부 글로우 효과를 내기 위해 비슷한 것을 할 수 있습니다.
public partial class AquaButton : UserControl
{
private bool m_IsMouseOver = false;
protected string m_text = string.Empty;
[Category("Appearance")]
[Description("Gets/Sets Button Text")]
[EditorBrowsable(EditorBrowsableState.Always), Browsable(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
Bindable(true)]
public override string Text
{
get { return m_text; }
set { m_text = value; this.Invalidate(); }
}
public AquaButton()
{
InitializeComponent();
}
private void AquaButton_Resize(object sender, EventArgs e)
{
this.Width = 130;
this.Height = 28;
}
private void AquaButton_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;
ExtendedGraphics eg = new ExtendedGraphics(g);
//SolidBrush br1 = new SolidBrush(Color.FromArgb(130, 125,236,255));
LinearGradientBrush br1 = new LinearGradientBrush(
new Point(60, 0),
new Point(60, 28),
Color.FromArgb(125, 236, 255),
Color.FromArgb(0, 130, 255)
);
eg.FillRoundRectangle(br1, 1, 1, 124, 25, 12);
if (m_IsMouseOver)
{
GraphicsPath GP = new GraphicsPath();
GP.AddEllipse(25, -7, 70, 70);
PathGradientBrush PGB = new PathGradientBrush(GP);
PGB.CenterColor = Color.FromArgb(0, 255, 0);
PGB.SurroundColors = new Color[] { Color.FromArgb(0, 0, 0, 0) };
g.FillRectangle(PGB, 0, 0, 130, 26);
}
Pen pn1 = new Pen(Color.Black, 2f);
eg.DrawRoundRectangle(pn1, 1, 1, 124, 25, 12);
Rectangle rect1 = new Rectangle(0, 0, this.Width, this.Height);
StringFormat strForm = new StringFormat();
strForm.Alignment = StringAlignment.Center;
strForm.LineAlignment = StringAlignment.Center;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
g.DrawString(m_text,
new Font(FontFamily.GenericSansSerif, 11, FontStyle.Bold),
Brushes.Black,
rect1,
strForm
);
}
private void AquaButton_MouseEnter(object sender, EventArgs e)
{
m_IsMouseOver = true;
this.Invalidate();
}
private void AquaButton_MouseLeave(object sender, EventArgs e)
{
m_IsMouseOver = false;
this.Invalidate();
}
}
Mac OS X에는이 기능이 내장되어 있습니다. 관심이 있으신가요? 'Graphics' 클래스를 사용하여 버튼을 사용자 정의 페인트해야합니다. 상태를 전환하면 색상이 변경되지 않습니다. 이것은 WinForms 응용 프로그램입니까? –
@CodyGray : IDE와 언어 그리고 다른 모든 것들을 의미합니까? – Mehrdad
@Walkerneo : 어떤 Windows 버전입니까? – Mehrdad