473,408 Members | 2,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 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 7560
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 Basic. I can live with alot of the major changes...
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. What I expect to see is the picture showing through...
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 controls with transparent backgrounds to the form. ...
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 change? Is there a way using the graphics to make...
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 ellipse looking fill in a rectangle - so the actual...
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 corner and a gradient shadow (6-7 different gray...
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 simulation of a shadow. I set BackColor of both...
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 over it while pictures and labels are being filled....
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 the controls on the form or the box I draw in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.