0

我想TextBoxGroupBox. 由于我是这个图形的新手,我很难找出问题所在。

这是我正在使用的代码:

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

此表单是辅助表单,当我单击主表单中的按钮时会显示该表单。当表单加载然后消失时,红色边框会出现一秒钟。

4

1 回答 1

2

您需要处理 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
于 2014-07-05T08:51:00.540 回答