我已经使用下面的代码创建了一个文本框,但是在文本框的任何情况下都不会触发 paint 方法。您能否提出触发 OnPaint() 的解决方案?
public class MyTextBox : TextBox
{
protected override void OnPaintBackground(PaintEventArgs pevent)
{
base.OnPaintBackground(pevent);
}
protected override void OnPaint(PaintEventArgs e)
{
ControlPaint.DrawBorder(e.Graphics,this.Bounds, Color.Red,ButtonBorderStyle.Solid);
base.OnPaint(e);
}
protected override void OnTextChanged(EventArgs e)
{
this.Invalidate();
this.Refresh();
base.OnTextChanged(e);
}
}
最佳答案
默认情况下,不会在 TextBox 上调用 OnPaint,除非您通过调用将其注册为自绘画控件:
SetStyle(ControlStyles.UserPaint, true);
例如来自您的 MyTextBox 构造函数。
关于c# - TextBox的OnPaint方法没有被调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37944323/