简体   繁体   English

文本框的边框未显示在GroupBox上

[英]Border of Textbox not shown op GroupBox

I use this code to change the color of the border of a textbox to red. 我使用此代码将文本框的边框颜色更改为红色。

private void Form1_Paint(object sender, PaintEventArgs e) {
      e.Graphics.DrawRectangle(new Pen(Brushes.Red, 3), 
        tb.Location.X-1, tb.Location.Y-1, tb.ClientRectangle.Width+ 5, 
        tb.ClientRectangle.Height + 5);
}

This works on a textbox that is directly on the Form but not when the textbox is in a groupbox. 这适用于直接位于窗体上的文本框,但不适用于该文本框在组框中的情况。 How should i do that ? 我该怎么办?

The form's Paint event cannot scribble on the group box, it has its own window. 窗体的Paint事件无法在组框上书写,它具有自己的窗口。 Windows are prevented from painting on each other. 防止Windows相互绘画。

You'll need to use the group box' Paint event. 您需要使用组框的“绘画”事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM