我想在GroupBox
中的TextBox
控件周围添加一个自定义边框。因为我是新来的,所以我很难弄清楚这个问题。
这是我使用的代码:
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
Dim _g As Graphics = Me.GroupBox1.CreateGraphics
Dim pen As New Pen(Color.Red, 2.0)
_g.DrawRectangle(pen, New Rectangle(TextBox1.Location, TextBox1.Size))
pen.Dispose()
End Sub
这个表单是次要表单,当我点击主表单中的按钮时,它会显示出来。红色边框在表单加载时出现一秒钟,然后消失。
您需要处理GroupBox绘制事件,而不是表单。
Private Sub HandleGroupBox1Paint(sender As Object, e As PaintEventArgs) Handles GroupBox1.Paint
Using p As New Pen(Color.Red, 2.0)
e.Graphics.DrawRectangle(p, Me.TextBox1.bound)
End Using
End Sub