小编Moi*_*nez的帖子

在TextBox C#中更改边框颜色

我有以下代码:

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);
   }
}
Run Code Online (Sandbox Code Playgroud)

这是完美的,但它没有显示文本,直到它得到焦点.

有谁能够帮我?怎么了?

预先感谢.

.net c# textbox winforms

7
推荐指数
2
解决办法
3万
查看次数

标签 统计

.net ×1

c# ×1

textbox ×1

winforms ×1