我使用了以下代码创建文本框,但是在任何情况下都没有触发绘画方法。你能否建议一个触发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);
}
}
DrawBorder
调用可能是无用的,因为你在之后才调用了base.OnPaint()
。所以TextBox
会再次绘制自己,覆盖掉你之前绘制的内容。 - René Vogt