在Groupbox内的Textbox周围绘制矩形

时间:2014-07-05 07:59:22

标签: vb.net graphics drawrectangle

我想在TextBox GroupBox控件中添加自定义边框。 由于我是这个图形新手的新手,我很难搞清楚这个问题。

这是我使用的代码:

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

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

1 个答案:

答案 0 :(得分: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
相关问题