[VB.Net]Health Bar
Posted: Sun Mar 20, 2011 10:25 pm
ChaosOverLord's Tutorials Present....
A Health Bar In VB.Net
So your making a game and you need a code for a health bar?
Well your in luck today because we got the tutorial for you!
Add 2 buttons and 1 textbox to the form.
Name button 1 Heal
Name button 2 Attack
Now time for some coding!
Declare these when your inside the coding....
Public BMap As New Bitmap(Me.Width, Me.Height, Me.CreateGraphics)
Public GraphicsBuffer As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(BMap)
Public HpBarG As Integer = 100
Public HpBarR As Integer = 100
Form 1 Load code
drawhpbar()
Then make this code below the form load code
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawImage(BMap, 0, 0)
End Sub
Next add this
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
For button 1 code add this
HpBarG += textbox1.Text
drawhpbar()
then for button 2 code add this
HpBarG -= textbox1.Text
drawhpbar()
Thank you for using my 3rd of all my tutorials!
A Health Bar In VB.Net
So your making a game and you need a code for a health bar?
Well your in luck today because we got the tutorial for you!
Add 2 buttons and 1 textbox to the form.
Name button 1 Heal
Name button 2 Attack
Now time for some coding!
Declare these when your inside the coding....
Public BMap As New Bitmap(Me.Width, Me.Height, Me.CreateGraphics)
Public GraphicsBuffer As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(BMap)
Public HpBarG As Integer = 100
Public HpBarR As Integer = 100
Form 1 Load code
drawhpbar()
Then make this code below the form load code
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawImage(BMap, 0, 0)
End Sub
Next add this
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
For button 1 code add this
HpBarG += textbox1.Text
drawhpbar()
then for button 2 code add this
HpBarG -= textbox1.Text
drawhpbar()
Thank you for using my 3rd of all my tutorials!