Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / October 2004

Tip: Looking for answers? Try searching our database.

Transparent form trouble

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Matthew - 15 Oct 2004 20:21 GMT
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
Bob Powell [MVP] - 16 Oct 2004 12:17 GMT
When you draw the text you need to set the TextRenderingHint of the Graphics
object to SingleBitPerPixel which ought to stop that problem.

Signature

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

> I created a transparent form, but the text in my label has a black border
> around it.
[quoted text clipped - 26 lines]
>
> Matthew
Matthew - 17 Oct 2004 17:38 GMT
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.