是否未调用TextBox OnPaint方法? [英] TextBox OnPaint method is not called?
本文介绍了是否未调用TextBox OnPaint方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码创建了一个TextBox,但在TextBox的任何情况下都不会触发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);
}
}
推荐答案
默认情况下不会在文本框上调用OnPaint,除非您通过调用:
将其注册为自绘制控件SetStyle(ControlStyles.UserPaint, true);
例如从MyTextBox构造函数。
这篇关于是否未调用TextBox OnPaint方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文