Question transparent image?

gixslayer

Member
Joined
Nov 8, 2008
Messages
19
Programming Experience
Beginner
Hey,

I am using VB.net and pictureboxes to draw images from .gif files. I'm making some kind of game. For that I need to make a map, I have the background (that's one of the pictureboxes) which is just a picture. But I need to draw images on top of that. But when I try to do that with pictureboxes the pictureboxes wont be transparent and show the picture behind. Instead they just have the same color as my forms background.

Anyone has any suggestions how i can do this?

I attached a picture.

Thanks,
gixslayer.
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    16.6 KB · Views: 42
Instead of putting your small images in separate picture boxes, read them into your program as bitmaps. For example:

Dim bmp1 as New Bitmap("D:\Pictures\Pic1.GIF")

You may have to make sure the right colour in the bitmap is transparent, for example:

bmp1.MakeTransparent(Color.White)

Then code the Paint event of the picture box which has your map as the background image. Use the Graphics object provided by the PaintEventArgs (e) to draw the bitmaps. For example:

e.Graphics.DrawImage(bmp1, x, y)

That assumes your bitmap is the right size. If you need to resize it, figure out the position and size of the target rectangle (rect) and use this version of DrawImage:

e.Graphics.DrawImage(bmp1, rect)


all the best, Vic
 
Back
Top