这是我用来创建面板和矩形的代码,但它不起作用:
Public ribbon_holder As New Panel
Public BluePen As New Pen(Main.mi_blue, 5)
With ribbon_holder
.Parent = Main
.Width = Main.Width
.Height = 75
.BackColor = Color.White
.BringToFront()
End With
Dim myGraphics As Graphics = ribbon_holder.CreateGraphics
myGraphics.DrawRectangle(BluePen, 0, 0, 100, 50)
我只是想在我的面板中创建一个空矩形。谢谢。
您可以使用
WithEvents
修饰符创建该变量,以便可以附加如下所示的 paint 事件:
Friend WithEvents ribbon_holder As New Panel
Private Sub rh_Paint(sender As Object, e As PaintEventArgs) Handles ribbon_holder.Paint
'GDI drawing in here persist
e.Graphics.DrawRectangle(BluePen, 0, 0, 100, 50)
End Sub