我是新來的編碼和嘗試的東西了。我希望有人能幫忙。我有一個代碼表示攻擊和治療的健康欄。不過,我想創建一個文本框,以數字格式指示健康狀況。我不知道如何解決這個問題。該txtHP.text是我想要的數字出現。這裏是我的代碼到目前爲止:VB NET,累計損壞
Public Class Form1
Dim bteNombre As Integer
Public DMap As New Bitmap(Me.Width, Me.Height, Me.CreateGraphics)
Public GraphicsBuffer As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(DMap)
Public HpBarG As Integer = 100
Public HpBarR As Integer = 100
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
DrawHpBar()
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawImage(DMap, 0, 0)
End Sub
Private Sub DrawHpBar()
If HpBarG < 0 Then
HpBarG = 0
End If
If HpBarG > 100 Then
HpBarG = 100
End If
GraphicsBuffer.DrawRectangle(Pens.Black, New Rectangle(47 - 1, 5 - 1, 100 + 1, 15))
GraphicsBuffer.FillRectangle(Brushes.Red, New Rectangle(47, 5, HpBarR, 14))
GraphicsBuffer.FillRectangle(Brushes.Lime, New Rectangle(47, 5, HpBarG, 14))
Me.Invalidate(New Rectangle(47 - 1, 5 - 1, 100 + 1, 15))
End Sub
Private Sub btnAttack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnAttack.Click
Randomize()
bteNombre = Int((10 - 1 + 1) * Rnd() + 1)
txtAtkHeal.Text = bteNombre.ToString
HpBarG -= txtAtkHeal.Text
DrawHpBar()
End Sub
Private Sub btnHeal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnHeal.Click
Randomize()
bteNombre = Int((5 - 1 + 1) * Rnd() + 1)
txtAtkHeal.Text = bteNombre.ToString
HpBarG += txtAtkHeal.Text
DrawHpBar()
txtHP.Text = bteNombre
End Sub
End Class
謝謝!
'myTextBox.Text = HpBarG'? – woz
感謝您發佈它,並且工作正常!並感謝您的幫助! – user3092463