Transparent form trouble

M

Matthew

I created a transparent form, but the text in my label has a black border
around it.
I created a new form with a label with the text color "red" and the
background color of "Transparent."
I added this code to the project:

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
hideMe(Me)
End Sub

Public Sub hideMe(ByVal obj As Object)
Dim Img As Bitmap = New Bitmap(1, 1)
obj.BackgroundImage = Img
obj.TransparencyKey = Img.GetPixel(0, 0)
End Sub

The result looks like this:
http://www.osbornewood.com/matthew/transp.gif

Notice the black border around the text.
Is this caused by anti-aliasing? Can it be turned off?

Also, the bitmap I create is black. Can I make it the "Control" color? It
looks sort of like tan, but I am not sure how to change the bitmap color in
code.

Thanks in advance,

Matthew
 
B

Bob Powell [MVP]

M

Matthew

When you draw the text you need to set the TextRenderingHint of the
Graphics
object to SingleBitPerPixel which ought to stop that problem.

Bob, thanks for the response. That's exactly what it wanted!

I had a bit of trouble figuring out how to apply it to the label, then I
realized I didn't have to!
I hid my Label1 and put the following in my form's paint event:
e.Graphics.TextRenderingHint = _
e.Graphics.TextRenderingHint.SingleBitPerPixel
e.Graphics.DrawString(Label1.Text, Label1.Font, _
New SolidBrush(Label1.ForeColor), New PointF(0, 0))

If there's a better way, please let me know. Otherwise, I am thrilled with
the result.

Thanks again!

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