![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
![]() |

|
| Programming Error ! Programming error messages |
![]() |
|
Transparent control in .net (currently using picturebox)
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Fixed Error!
Posts: 4,202
Join Date: Mar 2007
Rep Power: 6
IM:
|
pb.image = image The picturebox will not be transparent, it will get the parent forms background color. How can I make it be transparent? I have tried alot of things, for example: Dim bm As New Bitmap(pb.Image) bm.MakeTransparent(pb.BackColor) MyBase.Image = bm I tried to rewrite the Paint-event in the picturebox and trying to paint my picturebox with the graphic-object and using ColorMatrix to get an alpha on the background but I only succeed changing the alpha for the whole picture. I have also tried using a panel but nothing seems to work. If you have an idea of a form control that can hold a picture and have transparent background and that will solve my problem I will give you the points! Nothing I have tried works... Any suggestions? |
|
|
|
|
|
|
|
|
#2 (permalink) |
|
Fixed Error!
Posts: 4,202
Join Date: Mar 2007
Rep Power: 6
IM:
|
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. |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|