对于一般控件的显示,我们可以写一个类,继承系统的那个控件类,再override那个类的OnPaint方法,就可以改变控件的显示,这个对于textBox和label都是非常有效的方法,现在我想改变NumericUpDown这个控件的显示,在数字前面加上一个$符号,($就出现在控件里面,不是在控件前面加一个label),我override了系统NumericUpDown的OnPaint方法,但是却没有效果。。具体代码如下:
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);
SolidBrush drawBrush = new SolidBrush(this.ForeColor);
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Near;
// output string 
string displayText = "$" + this.Text;
e.Graphics.DrawString(displayText, this.Font, drawBrush, rect, sf);
}
我用同样的方法对label控件,是可以出效果,不知道问题出在哪里?请大家帮帮忙啊。。