我有以下代码:
这个功能运行良好,但是在获得焦点之前不会显示文本。有人能帮我吗?出了什么问题?
我有以下代码:
public class OurTextBox : TextBox
{
public OurTextBox()
: base()
{
this.SetStyle(ControlStyles.UserPaint, true);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Pen penBorder = new Pen(Color.Gray, 1);
Rectangle rectBorder = new Rectangle(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width - 1, e.ClipRectangle.Height - 1);
e.Graphics.DrawRectangle(penBorder, rectBorder);
}
}
这个功能运行良好,但是在获得焦点之前不会显示文本。有人能帮我吗?出了什么问题?
OnPaint
来为TextBox
绘制边框。相反,你应该在WndProc
中处理WM_NCPAINT
消息,并在非客户区绘制边框,就像这样。 - Reza Aghaei