By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,563 Members | 1,066 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,563 IT Pros & Developers. It's quick & easy.

Graphics gurus: transparent labels on gradient form?

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.