Image backgroud transparency color

  • Thread starter Thread starter Woody Splawn
  • Start date Start date
W

Woody Splawn

I have a button that I would like to put on a form, actually a panel on a
form. The problem is that it's transparency color is magenta and I can not
find a way to make the button look right. The image is that of a question
mark but behind it is magenta. I have looked for a setting in properties of
the button that will allow me to set the transparency color but I see
nothing. Could someone tell me how to do what I want.

Additonally. I think what I really need here is not a button but probably a
PictureBox object with an associated image. I would like to duplicate the
look and feel of the icons at the top of (for example) the properties
slideout in the Visual Studio Designer. Somehow they got those icons there,
I suppose it was by placing a picturebox with an associated image. Yes/No?
At any rate, I would like to have a help icon (a question mark) on my form
but without the magenta background.

If someone could help it would be appreciated.
 
At any rate, I would like to have a help icon (a question mark) on my form
but without the magenta background.

You need to load the image into a Drawing.Bitmap class, and then use the
..MakeTransparent method to prep the image, then set it as the background
property for your panel.


HTH

~
Jeremy
 
You need to load the image into a Drawing.Bitmap class

I'm sorry Jeremy, how does one load an image into a drawing bitmap class?
Are you talking about doing something in the properties of the PictureBox or
are you talking about doing something with code? If with code, how and in
what event?
 
I'm sorry Jeremy, how does one load an image into a drawing bitmap class?
Are you talking about doing something in the properties of the PictureBox or
are you talking about doing something with code? If with code, how and in
what event?

In code before the form loads, maybe in the constructor. I think there is
supposed to be support for a Transparent color via the TransparentColor
property though...


~
Jeremy
 
Hey Jeremy,

try the following in the Form's constructor:

Dim Img As Bitmap = Bitmap.FromFile("C:\myBMP.bmp")
Img.MakeTransparent()

'set as background for a test...
Me.BackgroundImage = Img

HTH

Félix Lima
Visual Basic and Visual Basic .NET


This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only.
 
Hi Woody,

You can try something like:

Dim img As Bitmap
img = Me.PictureBox1.Image
img.MakeTransparent()
Me.PictureBox1.Image = img

HTH

Félix Lima
Visual Basic and Visual Basic .NET


This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only.
 
Woody,
I did wanted to answer your question yesterday, because reading it, you
started to ask more and more.

This are as far as I can see the simplest sollutions not the nicest
With the IDE and the properties from a button
To get a button transparant, change the backcolor to "transparant" and do
not set a image on it, the image goes first (does not work on windows'95 it
think)
For a Question Mark, change the backcolor
And put a question mark with nice font in the text property
For a Button you can use a bmp file (wich you can make with visual studio
net file new file bitmapfile)
Beter is when you have tried that immidiatly to start using the imagelist
where in you can put your bitmaps and then select the button image from the
index from the imagelist. (very easy at runtime)
Cor
 
Hello,

Cor said:
This are as far as I can see the simplest sollutions not the nicest
With the IDE and the properties from a button
To get a button transparant, change the backcolor to "transparant" and do
not set a image on it, the image goes first (does not work on windows'95 it
think)
For a Question Mark, change the backcolor
And put a question mark with nice font in the text property

You can create a new Region (draw the string onto a GraphicsPath
(GraphicsPath.AddString)) and use the overloaded constructor to get a Region
from the GraphicsPath. This region can be assigned to the button's Region
property. If the user clicks on the transparent area of the button, the
click will be directed to the underlying control or form.

Regards,
Herfried K. Wagner
 
Beter is when you have tried that immidiatly to start using the imagelist
where in you can put your bitmaps and then select the button image from the
index from the imagelist. (very easy at runtime)

This is probably the easiest way to get a button on a form and have a bitmap
in the background with the Transparency color set the way you like.
However, sometimes I have problems with the way the bitmap looks inside the
button. It always seems to be offset a little to the right. I think this
is because of the shadowing that is, by default, part of the way a button
looks. I have tried various things to turn it off but haven't found the
right combination yet. Do you know off-hand how to get rid of anything
extra in the button (like shadowing) so the bitmap will center properly?
 
You mean something like this and please don't look what is in it, I just
have placed some text in it without thinking what
\\\\\\\\\\\\\
Dim ctr As Control ' vb 2002
ImageList1.ImageSize = New System.Drawing.Size(24, 24)
' For Each ctr As Control In Controls 'is new in vb2003 looks nicer
For Each ctr In Controls ' vb2002
If TypeOf ctr Is Button Then
Dim ctrbut As Button = CType(ctr, Button)
ctrbut.BackColor = Color.Black
ctrbut.Size = New System.Drawing.Size(26, 26)
ctrbut.FlatStyle = FlatStyle.Flat
ctrbut.text = ""
ctrbut.ForeColor = Color.Blue
ctrbut.Cursor = Cursors.Hand
ctrbut.ImageAlign = ContentAlignment.MiddleCenter
ctrbut.TextAlign = ContentAlignment.MiddleCenter
End If
Next
//////////
 
Back
Top