View Single Post
Old 29-Mar-2007, 02:55 AM   #2 (permalink)
Iphone
Fixed Error!
 
Iphone's Avatar

Posts: 4,202
Join Date: Mar 2007
Rep Power: 6 Iphone is on a distinguished road

IM:
Default Re: Transparent control in .net (currently using picturebox)

Place your transparent gif into a PictureBox (PictureBox1) as you have done before, and set its BackColor property to Transparent as zinno has shown you.

PictureBox1.BackColor = System.Drawing.Color.Transparent

On your form place a Panel Object (Panel1). Now set the parent property of your PictureBox to your Panel.

PictureBox1.Parent = Panel1

Now load up your map tiles into Images.

Dim grass As Image = Image.FromFile("c:\maps\grass.gif") ' or something like that
Dim road1 As Image = Image.FromFile("c:\maps\road1.gif")

In your Paint event for your panel, draw the tiles onto the panel to build your map:

Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
e.Graphics.DrawImage(grass, 50, 50)
e.Graphics.DrawImage(road1, 100, 50)
' etc.....
End Sub

Now you can move your PictureBox around the Panel like this

PictureBox1.Left = 65
PictureBox1.Top = 71

The transparent portions of your gif will take on the background colors of its parent container (the panel) that are directly below it. Since you painted your map tiles directly onto the panel with DrawImage(), you gif will appear above your map tiles correctly since it will take the backgound color of what ever it is above on the panel.
Iphone is offline   Reply With Quote