【发布时间】:2016-06-21 12:22:43
【问题描述】:
我使用下面的代码创建了一个文本框,但是在文本框的任何情况下都不会触发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);
}
}
【问题讨论】:
-
你调试没命中?你的
DrawBorder调用可能没用,因为你调用base.OnPaint()之后。所以TextBox再次覆盖你之前绘制的内容。
标签: c# .net winforms textbox onpaint