Dim energybar As New Rectangle(9, 154, energy, 21)
那是我的新矩形,现在当我绘制它时
e.Graphics.FillRectangle(Brushes.Blue, energybar)
它说没有宽度,但整数能量 = 到 100...
现在,我该如何解决这个问题?不过要简单一些...
您的代码有效。我把它放在一个 Form_Paint 事件中,导致下面的图像。我强烈怀疑您的能量变量的值是问题所在。确保如果变量未在Paint
方法中声明,则将其设为Class
Scoped 变量:
Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim energy As Integer = 100
Dim energybar As New Rectangle(9, 154, energy, 21)
e.Graphics.FillRectangle(Brushes.Blue, energybar)
End Sub