PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Framework Forms Transparent Label on Gradient Panel

Reply

Transparent Label on Gradient Panel

 
Thread Tools Rate Thread
Old 24-06-2003, 02:02 AM   #1
Mark Roebke
Guest
 
Posts: n/a
Default Transparent Label on Gradient Panel


Hello, I think I have a pretty simple problem, but have
spent a lot of time researching, only to find no 'real'
solution.

I have a Panel control that I'm filling with a gradient
using a LinearGradientBrush in the Paint event of the
Panel:

Control control = (Control)sender;
Graphics g = control.CreateGraphics();
g.Clear(Color.White);
Color startColor = Color.FromArgb(106, 127, 156);
Color endColor = Color.FromArgb(177, 197, 218);
LinearGradientBrush darkBrush = new LinearGradientBrush
(control.ClientRectangle, startColor, endColor,
LinearGradientMode.Vertical);
g.FillRectangle(darkBrush, control.ClientRectangle);
g.Dispose();

I have a Label control (on the Panel) that I want to
display transparent and thus show the Panel's gradient. I
have tried all the suggestions made in other posts
including:
Setting the BackColor of the Label to Transparent
Setting the Visible property of the Label to False and
then to True in code following the Paint event
Set the Label's Parent to the Panel in code

It doesn't seem to pick up what is drawn in the Paint
event, instead relying on the BackColor of the Panel set
at design time.

Any ideas?

Thanks,

Mark Roebke
RTP
  Reply With Quote
Old 24-06-2003, 12:54 PM   #2
md
Guest
 
Posts: n/a
Default Re: Transparent Label on Gradient Panel

Maybe you could use DrawString to draw the text rather than use a label.
Check it out in the help.

Matt


"Mark Roebke" <anonymous@rtp.com> wrote in message
news:5aa801c339f4$a1489d80$3101280a@phx.gbl...
> Hello, I think I have a pretty simple problem, but have
> spent a lot of time researching, only to find no 'real'
> solution.
>
> I have a Panel control that I'm filling with a gradient
> using a LinearGradientBrush in the Paint event of the
> Panel:
>
> Control control = (Control)sender;
> Graphics g = control.CreateGraphics();
> g.Clear(Color.White);
> Color startColor = Color.FromArgb(106, 127, 156);
> Color endColor = Color.FromArgb(177, 197, 218);
> LinearGradientBrush darkBrush = new LinearGradientBrush
> (control.ClientRectangle, startColor, endColor,
> LinearGradientMode.Vertical);
> g.FillRectangle(darkBrush, control.ClientRectangle);
> g.Dispose();
>
> I have a Label control (on the Panel) that I want to
> display transparent and thus show the Panel's gradient. I
> have tried all the suggestions made in other posts
> including:
> Setting the BackColor of the Label to Transparent
> Setting the Visible property of the Label to False and
> then to True in code following the Paint event
> Set the Label's Parent to the Panel in code
>
> It doesn't seem to pick up what is drawn in the Paint
> event, instead relying on the BackColor of the Panel set
> at design time.
>
> Any ideas?
>
> Thanks,
>
> Mark Roebke
> RTP



  Reply With Quote
Old 25-06-2003, 09:12 AM   #3
Bob Powell [MVP]
Guest
 
Posts: n/a
Default Re: Transparent Label on Gradient Panel

Controls aren't really transparent. They just find what is on the parent
background color and fill themselves with that. If the background is a
picture, it works out the particular bit of picture and uses that.

To make a control truly transparent you must override the CreateParams
property and modify the window style like so:

protected override CreateParams CreateParams

{

get

{

CreateParams cp = base.CreateParams;

cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT

return cp;

}

}



Then you need to set the control's BackColor to Color.Transparent in the
constructor.



Note that using the automatic double buffering on the control destroys the
effect so animated controls can flicker a bit using this technique.



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

Check out the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Buy quality Windows Forms tools
http://www.bobpowell.net/xray_tools.htm

Get the NEW must-have UI component. The .NET RectTracker
Enables CRectTracker like functionality for WindowsForms.
User defined layouts are a breeze.
http://www.bobpowell.net/recttracker.htm

"Mark Roebke" <anonymous@rtp.com> wrote in message
news:5aa801c339f4$a1489d80$3101280a@phx.gbl...
> Hello, I think I have a pretty simple problem, but have
> spent a lot of time researching, only to find no 'real'
> solution.
>
> I have a Panel control that I'm filling with a gradient
> using a LinearGradientBrush in the Paint event of the
> Panel:
>
> Control control = (Control)sender;
> Graphics g = control.CreateGraphics();
> g.Clear(Color.White);
> Color startColor = Color.FromArgb(106, 127, 156);
> Color endColor = Color.FromArgb(177, 197, 218);
> LinearGradientBrush darkBrush = new LinearGradientBrush
> (control.ClientRectangle, startColor, endColor,
> LinearGradientMode.Vertical);
> g.FillRectangle(darkBrush, control.ClientRectangle);
> g.Dispose();
>
> I have a Label control (on the Panel) that I want to
> display transparent and thus show the Panel's gradient. I
> have tried all the suggestions made in other posts
> including:
> Setting the BackColor of the Label to Transparent
> Setting the Visible property of the Label to False and
> then to True in code following the Paint event
> Set the Label's Parent to the Panel in code
>
> It doesn't seem to pick up what is drawn in the Paint
> event, instead relying on the BackColor of the Panel set
> at design time.
>
> Any ideas?
>
> Thanks,
>
> Mark Roebke
> RTP



  Reply With Quote
Old 25-06-2003, 11:47 PM   #4
Mark Roebke
Guest
 
Posts: n/a
Default Re: Transparent Label on Gradient Panel

Thanks Bob, that worked perfectly!

>-----Original Message-----
>Controls aren't really transparent. They just find what

is on the parent
>background color and fill themselves with that. If the

background is a
>picture, it works out the particular bit of picture and

uses that.
>
>To make a control truly transparent you must override

the CreateParams
>property and modify the window style like so:
>
> protected override CreateParams CreateParams
>
> {
>
> get
>
> {
>
> CreateParams cp = base.CreateParams;
>
> cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
>
> return cp;
>
> }
>
> }
>
>
>
>Then you need to set the control's BackColor to

Color.Transparent in the
>constructor.
>
>
>
>Note that using the automatic double buffering on the

control destroys the
>effect so animated controls can flicker a bit using this

technique.
>
>
>
>--
>Bob Powell [MVP]
>C#, System.Drawing
>
>Check out the GDI+ FAQ
>http://www.bobpowell.net/gdiplus_faq.htm
>
>Buy quality Windows Forms tools
>http://www.bobpowell.net/xray_tools.htm
>
>Get the NEW must-have UI component. The .NET RectTracker
>Enables CRectTracker like functionality for WindowsForms.
>User defined layouts are a breeze.
>http://www.bobpowell.net/recttracker.htm
>
>"Mark Roebke" <anonymous@rtp.com> wrote in message
>news:5aa801c339f4$a1489d80$3101280a@phx.gbl...
>> Hello, I think I have a pretty simple problem, but have
>> spent a lot of time researching, only to find no 'real'
>> solution.
>>
>> I have a Panel control that I'm filling with a gradient
>> using a LinearGradientBrush in the Paint event of the
>> Panel:
>>
>> Control control = (Control)sender;
>> Graphics g = control.CreateGraphics();
>> g.Clear(Color.White);
>> Color startColor = Color.FromArgb(106, 127, 156);
>> Color endColor = Color.FromArgb(177, 197, 218);
>> LinearGradientBrush darkBrush = new LinearGradientBrush
>> (control.ClientRectangle, startColor, endColor,
>> LinearGradientMode.Vertical);
>> g.FillRectangle(darkBrush, control.ClientRectangle);
>> g.Dispose();
>>
>> I have a Label control (on the Panel) that I want to
>> display transparent and thus show the Panel's

gradient. I
>> have tried all the suggestions made in other posts
>> including:
>> Setting the BackColor of the Label to Transparent
>> Setting the Visible property of the Label to False and
>> then to True in code following the Paint event
>> Set the Label's Parent to the Panel in code
>>
>> It doesn't seem to pick up what is drawn in the Paint
>> event, instead relying on the BackColor of the Panel

set
>> at design time.
>>
>> Any ideas?
>>
>> Thanks,
>>
>> Mark Roebke
>> RTP

>
>
>.
>

  Reply With Quote
Old 02-07-2003, 11:37 AM   #5
nitin.jain@megasoft.com
Guest
 
Posts: n/a
Default Re: Transparent Label on Gradient Panel

Hi Bob,

I have a panel which has to be downloaded on the web browser. I've
created a user control and added this panel into it. When I create
override the CreateParams in my panel, nothing gets downloaded on the
browser. Do I need to do something different for the web.

Thanks,
Nitin
"Mark Roebke" <anonymous@rtp.com> wrote in message news:<01ca01c33b74$2e505e90$a401280a@phx.gbl>...
> Thanks Bob, that worked perfectly!
>
> >-----Original Message-----
> >Controls aren't really transparent. They just find what

> is on the parent
> >background color and fill themselves with that. If the

> background is a
> >picture, it works out the particular bit of picture and

> uses that.
> >
> >To make a control truly transparent you must override

> the CreateParams
> >property and modify the window style like so:
> >
> > protected override CreateParams CreateParams
> >
> > {
> >
> > get
> >
> > {
> >
> > CreateParams cp = base.CreateParams;
> >
> > cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
> >
> > return cp;
> >
> > }
> >
> > }
> >
> >
> >
> >Then you need to set the control's BackColor to

> Color.Transparent in the
> >constructor.
> >
> >
> >
> >Note that using the automatic double buffering on the

> control destroys the
> >effect so animated controls can flicker a bit using this

> technique.
> >
> >
> >
> >--
> >Bob Powell [MVP]
> >C#, System.Drawing
> >
> >Check out the GDI+ FAQ
> >http://www.bobpowell.net/gdiplus_faq.htm
> >
> >Buy quality Windows Forms tools
> >http://www.bobpowell.net/xray_tools.htm
> >
> >Get the NEW must-have UI component. The .NET RectTracker
> >Enables CRectTracker like functionality for WindowsForms.
> >User defined layouts are a breeze.
> >http://www.bobpowell.net/recttracker.htm
> >
> >"Mark Roebke" <anonymous@rtp.com> wrote in message
> >news:5aa801c339f4$a1489d80$3101280a@phx.gbl...
> >> Hello, I think I have a pretty simple problem, but have
> >> spent a lot of time researching, only to find no 'real'
> >> solution.
> >>
> >> I have a Panel control that I'm filling with a gradient
> >> using a LinearGradientBrush in the Paint event of the
> >> Panel:
> >>
> >> Control control = (Control)sender;
> >> Graphics g = control.CreateGraphics();
> >> g.Clear(Color.White);
> >> Color startColor = Color.FromArgb(106, 127, 156);
> >> Color endColor = Color.FromArgb(177, 197, 218);
> >> LinearGradientBrush darkBrush = new LinearGradientBrush
> >> (control.ClientRectangle, startColor, endColor,
> >> LinearGradientMode.Vertical);
> >> g.FillRectangle(darkBrush, control.ClientRectangle);
> >> g.Dispose();
> >>
> >> I have a Label control (on the Panel) that I want to
> >> display transparent and thus show the Panel's

> gradient. I
> >> have tried all the suggestions made in other posts
> >> including:
> >> Setting the BackColor of the Label to Transparent
> >> Setting the Visible property of the Label to False and
> >> then to True in code following the Paint event
> >> Set the Label's Parent to the Panel in code
> >>
> >> It doesn't seem to pick up what is drawn in the Paint
> >> event, instead relying on the BackColor of the Panel

> set
> >> at design time.
> >>
> >> Any ideas?
> >>
> >> Thanks,
> >>
> >> Mark Roebke
> >> RTP

> >
> >
> >.
> >

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off