Transparent form, opaque label

M

Matthew

I have Visual Basic .NET 2003, and wanted to create a form that only shows
the contents of a label.
The form can't have a title bar or border. It seriously needs to just be
the text inside the label.

Can this be done?

Matthew
 
M

Matthew

I have Visual Basic .NET 2003, and wanted to create a form that only shows
the contents of a label.

Me.FormBorderStyle = FormBorderStyle.None
Me.ControlBox = False
Me.TransparencyKey = Me.BackColor

I found the above code, and it makes everything go away except the
background for my label. I have tried setting the background color of the
label to transparent, but it is still an ugly grey color.

Matthew
 
M

Matthew

I have Visual Basic .NET 2003, and wanted to create a form that only shows
the contents of a label.

Me.FormBorderStyle = FormBorderStyle.None
Me.ControlBox = False
Me.TransparencyKey = Me.BackColor

I found the above code, and it makes everything go away except the
background for my label. I have tried setting the background color of the
label to transparent, but it is still an ugly grey color.

Matthew
 
2

23s

How about this:

Set the form border style to None

Set the background color of the form to some color you aren't likely to use,
like 'Magenta' (bright pink).

Set the transparency key of the form to Magenta (or whatever color you chose
above)

Put a label on the form. Set the label's background color to 'Transparent'.
Populate the label with some text, run the app / show the form and you
should only see the label text. Note this was tested in WinXP SP2, dunno if
other/older OS's have transparency issues with forms.
 
M

Matthew

Set the form border style to None
Set the background color of the form to some color you aren't likely to
use, like 'Magenta' (bright pink).

Set the transparency key of the form to Magenta (or whatever color you
chose above)

Put a label on the form. Set the label's background color to
'Transparent'. Populate the label with some text, run the app / show the
form and you should only see the label text. Note this was tested in
WinXP SP2, dunno if other/older OS's have transparency issues with forms.

Thanks for the response. I also have XP SP2. What a happy coincidence!

I folowed your steps, but the background of the label was Magenta. Was
there another setting you might have modified?
Or, if you have a working example, could you send it to me?

Thanks,

Matthew
 
M

Matthew

I have Visual Basic .NET 2003, and wanted to create a form that only shows
the contents of a label.
The form can't have a title bar or border. It seriously needs to just be
the text inside the label.

I think I figured it out.

Me.FormBorderStyle = FormBorderStyle.None
Dim Img As Bitmap = New Bitmap(10, 10)
Img.MakeTransparent(Img.GetPixel(1, 1))
Me.BackgroundImage = Img
Me.TransparencyKey = Img.GetPixel(1, 1)

For some reason, having the background as an image seems to be more
effective than making the TransparencyKey the BackColor:
Me.TransparencyKey = Me.BackColor

Matthew
 

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