PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
Transparent Label on Gradient Panel
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
Transparent Label on Gradient Panel
![]() |
Transparent Label on Gradient Panel |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#4 |
|
Guest
Posts: n/a
|
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 > > >. > |
|
|
|
#5 |
|
Guest
Posts: n/a
|
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 > > > > > >. > > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

