472,347 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Graphics gurus: transparent labels on gradient form?

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 form are made
transparent. What results is the label's backcolor appearing as blocks of
'control' colored background. Setting the label's backcolor to
color.transparent does not make it transparent (evidently the text is
repainted with a control-colored backcolor. Here is the code. Do any of
you graphics gurus know of a way to make the labels appear transparent in
front of a gradient form background?

Private Sub frmAdminActivity_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

'gradient form background routine:

Dim x As Integer = Me.Width

Dim y As Integer = Me.Height

Dim g As Graphics = Me.CreateGraphics

Dim lgBrush As New LinearGradientBrush(New Point(0, 0), New Point(x,
y), _

Color.FromArgb(190, 190, 190),
Color.WhiteSmoke)

g.FillRectangle(lgBrush, 0, 0, x, y)

g.Dispose()

'transparent label routine:

Dim ctl As Control

Dim str As String

For Each ctl In Me.Controls

str = ctl.GetType.ToString

If str = "System.Windows.Forms.Label" Then

ctl.BackColor = System.Drawing.Color.Transparent

End If

Next
Nov 21 '05 #1
2 7464
You need to create a truly transparent control. See Windows Forms Tips and
Tricks.

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

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

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

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Dean Slindee" <sl*****@charter.net> wrote in message
news:yd****************@fe02.lga...
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 form are made
transparent. What results is the label's backcolor appearing as blocks of
'control' colored background. Setting the label's backcolor to
color.transparent does not make it transparent (evidently the text is
repainted with a control-colored backcolor. Here is the code. Do any of
you graphics gurus know of a way to make the labels appear transparent in
front of a gradient form background?

Private Sub frmAdminActivity_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

'gradient form background routine:

Dim x As Integer = Me.Width

Dim y As Integer = Me.Height

Dim g As Graphics = Me.CreateGraphics

Dim lgBrush As New LinearGradientBrush(New Point(0, 0), New Point(x,
y), _

Color.FromArgb(190, 190, 190),
Color.WhiteSmoke)

g.FillRectangle(lgBrush, 0, 0, x, y)

g.Dispose()

'transparent label routine:

Dim ctl As Control

Dim str As String

For Each ctl In Me.Controls

str = ctl.GetType.ToString

If str = "System.Windows.Forms.Label" Then

ctl.BackColor = System.Drawing.Color.Transparent

End If

Next

Nov 21 '05 #2
don't use CreateGraphics.

The PaintEventArgs has a Graphics reference, use that and don't dispose it
since you didn't create it.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Dean Slindee" <sl*****@charter.net> wrote in message
news:yd****************@fe02.lga...
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 form are made
transparent. What results is the label's backcolor appearing as blocks of
'control' colored background. Setting the label's backcolor to
color.transparent does not make it transparent (evidently the text is
repainted with a control-colored backcolor. Here is the code. Do any of
you graphics gurus know of a way to make the labels appear transparent in
front of a gradient form background?

Private Sub frmAdminActivity_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

'gradient form background routine:

Dim x As Integer = Me.Width

Dim y As Integer = Me.Height

Dim g As Graphics = Me.CreateGraphics

Dim lgBrush As New LinearGradientBrush(New Point(0, 0), New Point(x,
y), _

Color.FromArgb(190, 190, 190),
Color.WhiteSmoke)

g.FillRectangle(lgBrush, 0, 0, x, y)

g.Dispose()

'transparent label routine:

Dim ctl As Control

Dim str As String

For Each ctl In Me.Controls

str = ctl.GetType.ToString

If str = "System.Windows.Forms.Label" Then

ctl.BackColor = System.Drawing.Color.Transparent

End If

Next

Nov 21 '05 #3

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

Similar topics

4
by: Matthew | last post by:
I am not the most talented programmer to grace the earth by a long shot. But I've got a gripe I need to air about the .NET implementaion of Visual...
2
by: Steve Barnett | last post by:
I've got a form on which there is a picture box with a picture in it. On top of that I place two labels and make their backgrounds transparent....
1
by: Robert W. | last post by:
I've successfully implemented code to change a form's background to a nice blue gradient. It looks great! But I'm having problems adding...
13
by: SStory | last post by:
I need to be able to give the appearance of glass over a picture inside of a frame. How can I do this in real time given that the picture will...
4
by: Adam Maltby | last post by:
Hi, I need to do a transparent label but with a difference. I have drawn on my form a custom background using CreateGraphics as I needed an...
0
by: Emil | last post by:
Hi all, I have a big big Problem, I never had before. The company I work for, wants a very special dialog. Imagine a Dialog which has rounded...
3
by: vul | last post by:
I used to use creating headers (label at the top of the screen) for VB6 forms as 2 labels shifted a little bit with different for colors to get a...
3
by: will_456 | last post by:
I have a form containing many controls which receive their properties at design time. Trouble is the form displays large transparent squares all...
0
by: =?Utf-8?B?QW5kcmV3?= | last post by:
I have a borderless form that has a transparent background. I only wanted the color that I painted the background with to be transparent and not...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

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.