public Color ImpressBackColor
{
get {
return impressBackColor;
}
set {
impressBackColor = value;
Invalidate();
}
} public Color ImpressForeColor
{
get
{
return impressForeColor;
}
set
{
impressForeColor = value;
Invalidate();
}
} protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
Graphics g = pe.Graphics;
if (!IsPress)
{
Pen pen = new Pen(BorderColor);
pen.Width = BorderSize;
GraphicsExtension.DrawRoundedRect(g, pen, BackColor, new Rectangle(0, 0, this.Width - 1, this.Height - 1), new Size(RoundCornerSize, RoundCornerSize));
//渐变
//GraphicsExtension.FillGradientRectangle(g, new Rectangle(0, 0, this.Width - 1, this.Height - 1), Color.White, Color.Black, FillDirection.TopToBottom);
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
g.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), new Rectangle(0, 0, this.Width - 1, this.Height - 1), sf);
}
else
{
Pen pen = new Pen(BorderColor);
pen.Width = BorderSize;
GraphicsExtension.DrawRoundedRect(g, pen, impressBackColor, new Rectangle(0, 0, this.Width - 1, this.Height - 1), new Size(RoundCornerSize, RoundCornerSize));
//渐变
//GraphicsExtension.FillGradientRectangle(g, new Rectangle(0, 0, this.Width - 1, this.Height - 1), Color.White, Color.Black, FillDirection.TopToBottom);
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
g.DrawString(this.Text, this.Font, new SolidBrush(this.ImpressForeColor), new Rectangle(0, 0, this.Width - 1, this.Height - 1), sf);
}
}
把base.OnPaint(pe);放在绘制代码之前,放到后面的话就由系统绘制覆盖你之前绘制的...