我重写了button的onpain方法后,text无法显示到button上..代码如下
protected override void OnPaint(PaintEventArgs e)
{
Graphics g=e.Graphics;
SelfDramImg(g,0);
//如果加下面代码,text就能正常显示.但是OnPaint方法等于没用了..
//系统会重修绘制button...不加的话就不能在button上显示文字
//base.OnPaint(e);
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g=e.Graphics;
SelfDramImg(g,0);
//如果加下面代码,text就能正常显示.但是OnPaint方法等于没用了..
//系统会重修绘制button...不加的话就不能在button上显示文字
//base.OnPaint(e);
}
Graphics g=e.Graphics;
StringFormat drawFormat = new StringFormat();
drawFormat.FormatFlags = StringFormatFlags.DisplayFormatControl;
drawFormat.LineAlignment=StringAlignment.Center;
drawFormat.Alignment=System.Drawing.StringAlignment.Center;
g.DrawString(this.Text,this.Font,new LinearGradientBrush(this.ClientRectangle,Color.Black,Color.Black,LinearGradientMode.Vertical),this.ClientRectangle,drawFormat);