Search code examples
vbavisual-studiopicturebox

Decrease picturebox width from left to right making HP bar for RPG game


i want to create 2 HP bar(left/right) using visual basic, i used

hp1.width -=10

to decrease left sided hp like this but when i used it to the right sided it becomes like this i used

hp2.Left += 10
hp2.Width -= 10

for the right sided how to make the right sided hp bar decreased from left to right?


Solution

  •     dim hp as integer = 0
        hp += 10
        '189 for width, 22 for height
        Dim rect As Rectangle = New Rectangle(hp, 0, 189, 22)
        Dim bit As Bitmap = New Bitmap(My.Resources.HPBar_Right, 189, 22)
        Dim cropBitmap = New Bitmap(189, 22)
        Dim g As Graphics = Graphics.FromImage(cropBitmap)
        g.DrawImage(bit, 0, 0, rect, GraphicsUnit.Pixel)
        hp2.Image = cropBitmap
        hp2.Left += 10
        hp2.Refresh()