making image and picturebox transparent

G

Guest

in my app i must have several pictureboxes over the others. Some pictureboxes
just have a couple of lines or rectangles, and absolutly nothing more but the
image is an .BMP. So, my problem is that i need to see whats beind those
pictureboxes and at the same time showing, the lines and rectangles that
exist on the pictureboxes that are at the top. Because i just can't copy the
image to the other picturebox (because i'll have to be able to control that
image, later) i need to know how can i turn transparant the pictureboxes that
are at the top. I've tryed the following code but it didn't work because what
it does is to copy the background color of the main picturebox to the
picturebox at the top

dim Logo as new Bitmap(CompanyLogo.Image)
Logo.MakeTransparent(Logo.GetPixel(1,1))
CompanyLogo.Image=Logo;
 
K

Ken Tucker [MVP]

Hi,

The picturebox does not have a transparent color property. I
would use a form instead.

Dim frm As Form

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
PictureBox1.BackgroundImage = Image.FromFile("C:\bliss.bmp")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim bm As New Bitmap(PictureBox1.Width, PictureBox1.Height)
Dim g As Graphics = Graphics.FromImage(bm)
g.Clear(Color.White)
g.FillEllipse(Brushes.Red, 20, 20, 20, 20)
bm.MakeTransparent(Color.White)
g.Dispose()
frm = New Form
With frm
.FormBorderStyle = FormBorderStyle.None
.Size = PictureBox1.Size
.TopLevel = False
.Parent = PictureBox1
.BringToFront()
.TransparencyKey = SystemColors.Control
.BackgroundImage = bm
.Show()
End With
End Sub

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top