嗨我尝试制作一个自定义按钮,其渐变颜色在单击另一个按钮时会发生变化。这是我喜欢的代码
public class GradientButton : Button
{
private Color _Color1 = Color.LightSteelBlue;
private Color _Color2 = Color.White;
private Color _Color3 = Color.Orange;
private Color _Color4 = Color.LightSteelBlue;
public Color TopColor
{
get { return _Color1; }
set { _Color1 = value; }
}
public Color BottomColor
{
get { return _Color1; }
set { _Color1 = value; }
}
public Color FocusColor
{
get { return _Color3; }
set { _Color3 = value; }
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
using (var brush = new LinearGradientBrush(this.ClientRectangle, _Color1, _Color2, LinearGradientMode.Vertical))
{
e.Graphics.FillRectangle(brush, this.ClientRectangle);
}
}
protected override void OnGotFocus(EventArgs e)
{
base.OnGotFocus(e);
_Color1 = _Color3;
this.Invalidate();
}
protected override void OnLostFocus(EventArgs e)
{
base.OnLostFocus(e);
_Color1 = _Color4;
this.Invalidate();
}
public GradientButton()
{
}
}
进行控制,当ai在设计模式下将其放置在表格上时,渐变是LightSteelBlue到白色,正如我所料。但是,当我运行表单时,无论是否单击,该按钮都会变为橙色。我怎样才能证明这个