[VB.Net]Health Bar
Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
8 posts
Page 1 of 1
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!
You do not have the required permissions to view the files attached to this post.
Good tut im gonna try it now but next time make to use the code thingo coz people will have a cry , like me 

PLEASE use the CODE tags:
You tutorials is good, but use the CODE tags!! Please, im begging!
Code: Select all
[/code][code]
You tutorials is good, but use the CODE tags!! Please, im begging!
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
![Image]()
![Image]()
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!

also how can we use two of these say for an Energy Bar
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that 

Looks nice, I've been trying to code a text based rpg for a while now, but the healthbar I made wasn't good at all...
wait i got lost in the code could you explain it to me i know what this means
Code: Select all
but what does this "do" 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
Code: Select all
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
Ehh... no.
Code: Select all
That's a very big no-no. If the user enters anything but a number, you're program will not work the way you want it to. Do this instead:
HpBarG += textbox1.Text
Code: Select all
Also, why did you make this cost 5 credits? It's not that hard of a "program" and you have the source listed there.Dim newHP As Integer = Val(TextBox1.Text)
HpBarG += newHP
8 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023