Transparent Label in .NET Compact framework

No.of Views2061
Bookmarked0 times
Downloads 
Votes0
By  RRaveen   On  15 Feb 2010 22:02:46
Tag : .NET CF , How to
Transparent Label in .NET Compact framework
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Hi Guys,

I have seen in MS forums lot of developers asking how to make transparent label. Actually it is pretty simple, when we use the Graphics object in .NET CF.

Here is the complete code for create transparent label.

 

private void DrawLabel (Label label, Graphics gfx)
{
if (label.TextAlign == ContentAlignment.TopLeft)
{
gfx.DrawString(label.Text, label.Font, new SolidBrush(label.ForeColor), label.Bounds);
}
else if (label.TextAlign == ContentAlignment.TopCenter)
{
SizeF size = gfx.MeasureString(label.Text, label.Font);
float left = ((float) this.Width + label.Left) / 2 - size.Width / 2;
RectangleF rect = new RectangleF(left, (float) label.Top, size.Width, label.Height);
gfx.DrawString(label.Text, label.Font, new SolidBrush(label.ForeColor), rect);
}
else //is aligned at TopRight
{
SizeF size = gfx.MeasureString(label.Text, label.Font);
float left = (float) label.Width - size.Width + label.Left;
RectangleF rect = new RectangleF(left, (float) label.Top, size.Width, label.Height);
gfx.DrawString(label.Text, label.Font, new SolidBrush(label.ForeColor), rect);
}
}

I hope this is helpful.

 
Sign Up to vote for this article
 
About Author
 
RRaveen
Occupation-Software Engineer
Company-TGS
Member Type-Gold
Location-Singapore
Joined date-03 Jun 2009
Home Page-codegain.com
Blog Page-www.codegain.com
- B.Sc. degree in Computer Science. - 4+ years experience in Visual C#.net and VB.net - Obsessed in OOP style design and programming. - Designing and developing Network security tools. - Designing and developing a client/server application for sharing files among users in a way other than FTP protocol. - Designing and implementing GSM gateway applications and bulk messaging. - Windows Mobile and Symbian Programming - Having knowledge with ERP solutions
 
 
Other popularSectionarticles
Comments
By:RRaveenDate Of Posted:9/9/2010 7:09:11 AM
Like this way
You have to use protected override void OnPaint(PaintEventArgs e) { // here you have to write ur code. } if you have any questions, please ask in codegain message board to get faster response. thank you
By:NicoDate Of Posted:9/9/2010 5:13:03 AM
re
Hi, where I call this function and how I get the Graphics parameter? Under .NET CF I do not have any OnPaint event or something like that. Thanks
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top