469,936 Members | 2,444 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,936 developers. It's quick & easy.

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 7278
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Steve Barnett | last post: by
13 posts views Thread by SStory | last post: by
3 posts views Thread by vul | last post: by
reply views Thread by =?Utf-8?B?QW5kcmV3?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.