Layering Images or Textbox on top of a picture

Biohazard

Well-known member
Joined
Nov 23, 2009
Messages
52
Programming Experience
5-10
Okay so here is the problem
I designed a countdown animation that cycles through 64 pictures.
This works for the most part now the problem is I want to put a number on top of that picture without having to reformat the pictures because it counts up to 10. If I have to reformat the picture it will have to be done 64 times for each sequence creating the problem, I will have to make 640 png files and that is too much to do. Not including the coding!

Why I am saying this approach would have to be done is because when I but a Label ontop, it chooses Grey as the background of the number, even when I set the background to web transparent. So I tried another approach, I layered a picture of the number with a transparent background in hopes to see the countdown sequence but that didn't work either Grey again, even when I set it's background to transparent.

IS THERE SOMETHING I AM DOING WRONG??

Attached is a picture of how it renders:
Upload-1.png
 
I think I found the solution but I can't quite get it to work just yet maybe someone can help??

Here is what I found, Pictureboxes and other controls don't quite render transparency, instead it the term transparent means it sets the backcolor to it's parents color.

So here is what I found, I have to draw the image (which has transparency) manually
And here is how I did it:
VB.NET:
 e.Graphics.DrawImage(Image.FromFile(Application.StartupPath & "\Data\CountDown\Numbers\00.png"), New PointF(58, 60))

The issue is that I cannot get it to render my image ontop of the picturebox

What happens is it draws the image in the location of the picturebox but it doesn't show my drawing

WHAT IS THE SOLUTION??
 
And when I do the e.graphics is it possible to erase it because after the underlying picturebox cycles through all the images so I can redraw a different image???
 
Biohazard said:
VB.NET:
e.Graphics.DrawImage(Image.FromFile(Application.StartupPath & "\Data\CountDown\Numbers\00.png"), New PointF(58, 60))
The issue is that I cannot get it to render my image ontop of the picturebox
Which Paint event are you using, Form or Picturebox?
VB.NET:
And when I do the e.graphics is it possible to erase it because after the underlying picturebox cycles through all the images so I can redraw a different image???
You "erase" by invalidating/refreshing the control, Paint event then gets called again. You can use a variable to determine what to dynamically draw.
 
So is there a way that I could set the Paint event to every time my timer
ticks 64 times??

I am not on my development computer right now but,
would the code look somewhat like this:

VB.NET:
Dim intcount as integer
Private Sub Timer1.Tick(...etc...)
           intcount +=1
           If intcount <= 64 then e.Graphics.DrawImage(Image.FromFile(Application.StartupPath & "\Data\CountDown\Numbers\00.png"), New PointF(58, 60))
           If intcount <= 128 then
 e.Graphics.DrawImage(Image.FromFile(Application.StartupPath & "\Data\CountDown\Numbers\01.png"), New PointF(58, 60))

End if
End Sub
 
You "erase" by invalidating/refreshing the control, Paint event then gets called again.
To invalidate/refresh the control you can use the Invalidate/Refresh methods :)
 
Hey John thanks very much I am new to GDI development in a sense I have been stuck in N00b mode for a 5 or so years now but I learn as I develop
 
Back
Top