473,395 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Transparent form trouble

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
Nov 21 '05 #1
2 1533
When you draw the text you need to set the TextRenderingHint of the Graphics
object to SingleBitPerPixel which ought to stop that problem.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml


"Matthew" <tu*************@alltel.net> wrote in message
news:uM**************@TK2MSFTNGP12.phx.gbl...
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

Nov 21 '05 #2
> 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
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Graphics_master | last post by:
Anyone know how to create a transparent splash screen similar to Photoshop, After Effects, or premiere. They have a wonderful transparent look. I realize that I can use the key color property of...
9
by: don | last post by:
I want to create a transparent form and can write something on it by using Ink. I try to set form.backcolor = color.transparent, but it dosen't accept. And everything will be transprent when i use...
3
by: Steve Koon | last post by:
Any thoughts on getting this project to work or suggesting another method would be appreciated. Steve ========================================== Project: A Windows Form which acts as a...
8
by: Grahammer | last post by:
Is it possible to set the background of a usercontrol as transparent? I tried setting the background image of the usercontrol to a transparent GIF, but that caused MAJOR problems. I'm making...
0
by: Henry Wu | last post by:
Hi, I am aware that TransparencyKey only works with top-level forms or Non-MDI Child Forms, if one tries to set the opacity or transparencykey property to a MDI-Child form, it will have no effect....
2
by: Dean Slindee | last post by:
It appears that I have two routines that don't play well together! First routine: a form's background is shaded with a gradient color. Second routine: then, the background of all labels on the...
4
by: ray well | last post by:
in my app i need to make a RichTextbox control transparent. i need it to be a like a pane of glass lying on a sheet of paper, where u can see everything on the sheet of paper not covered by text...
8
by: MikeB | last post by:
Hi, I created a picturebox with a map as an image. I want to make certain areas on the map clickable hotspots and the way I'm trying to do this is to create a transparent label with a different...
8
by: Brian Ward | last post by:
I am looking for a simple way to set the image transparency in a PictureBox. I have a moving PictureBox containing a graphic image .. moving by incrementing its Left property. The background...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.