矩形宽度(可能很容易回答)VB

时间:2012-05-02 03:36:51

标签: vb.net variables resize

Dim energybar As New Rectangle(9, 154, energy, 21)

这是我的新矩形,现在当我画它时

e.Graphics.FillRectangle(Brushes.Blue, energybar)

它表示没有宽度,但整数能量= = 100 ......

现在,我该如何解决这个问题?但它有点简单......

1 个答案:

答案 0 :(得分:0)

您的代码有效。我把它放在一个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

enter image description here