Seeking: Panel Opacity & Border
-
Hello, Beginning with the hard bit first, I have recently started looking for a way to control a panel's background's opacity, and have not encountered a fully explained C# solution (though there are quite a lot of VB ones, which I sadly only managed to gape at without understanding a thing). I have seen the way to make it completely transparent[^], and I have encountered a way to create opacity for a PictureBox's image[^]... but attempts to combine the two have failed miserably. I assume that once I get the transparent background thing going, drawing a non-transparent border (perhaps using some of the code from here[^]) would be easy enough to figure out (though if it clashes with the opacity goal, then I would like to know how/why). I'd appreciate any tips/links/code bits/etc. Thanks.
-M.
Hello, I had the same problem, by using a backgroundimage on a Form. There are some solution (property "TransparencyKey") that are not working for every graphic card. This works:
Bitmap bm = new Bitmap(...); Color transparent = bm.GetPixel(0,0); bm.MakeTransparent(transparent); this.BackgroundImage = bm;
What I found out is, that you can not change the opacity after you made it transparent. (Ok, you can but transparency doesn't work after that.) After you change opacity you have to "MakeTransparent" again. I know it's not much, but maybe it helps. All the best, Martin -
Hello, I had the same problem, by using a backgroundimage on a Form. There are some solution (property "TransparencyKey") that are not working for every graphic card. This works:
Bitmap bm = new Bitmap(...); Color transparent = bm.GetPixel(0,0); bm.MakeTransparent(transparent); this.BackgroundImage = bm;
What I found out is, that you can not change the opacity after you made it transparent. (Ok, you can but transparency doesn't work after that.) After you change opacity you have to "MakeTransparent" again. I know it's not much, but maybe it helps. All the best, MartinHmm... I think there may have been a misunderstanding. What I'm trying to do is create a panel with opacity, so that when I move it around over other controls, the other controls are visible under it, but the panel's background is still shown, just faded according to its opacity value. Something to the effect of looking at the world through a piece of colored cellophane... If I understand your suggestion correctly, that code will make my panel transparent, but I want it to still be visible, but faded.
-M.
-
Hmm... I think there may have been a misunderstanding. What I'm trying to do is create a panel with opacity, so that when I move it around over other controls, the other controls are visible under it, but the panel's background is still shown, just faded according to its opacity value. Something to the effect of looking at the world through a piece of colored cellophane... If I understand your suggestion correctly, that code will make my panel transparent, but I want it to still be visible, but faded.
-M.
-
Hmm... I think there may have been a misunderstanding. What I'm trying to do is create a panel with opacity, so that when I move it around over other controls, the other controls are visible under it, but the panel's background is still shown, just faded according to its opacity value. Something to the effect of looking at the world through a piece of colored cellophane... If I understand your suggestion correctly, that code will make my panel transparent, but I want it to still be visible, but faded.
-M.
-
I don't understand... why should I create an entire form just to have a customized panel? I'm just looking for a a piece of code to stick in the OnPaint method of a custom panel that'll make it's background have opacity... I've seen it done in VB, but was unable to translate it to C#.
-M.
-
Hello,
adrianna_r wrote:
If I understand your suggestion correctly, that code will make my panel transparent, but I want it to still be visible, but faded.
Only the color of the specified bixel will be transparent. Martin
...But I don't want full transparency on any bit of the panel, just opacity. I want it to look like in this Photoshopped-ed image[^]. (the blue panel isn't fully transparent, but you can still see stuff under it, such as that button)
-M.
-
...But I don't want full transparency on any bit of the panel, just opacity. I want it to look like in this Photoshopped-ed image[^]. (the blue panel isn't fully transparent, but you can still see stuff under it, such as that button)
-M.
-
...But I don't want full transparency on any bit of the panel, just opacity. I want it to look like in this Photoshopped-ed image[^]. (the blue panel isn't fully transparent, but you can still see stuff under it, such as that button)
-M.
Hello, Have you tried changeing the Alpha Level of the BackColor. this.BackColor=Color.FromArgb(128,this.BackColor); All the best, Martin -- modified at 7:43 Wednesday 29th November, 2006 Have it from here. Tried it, but doesn't work????? http://www.eggheadcafe.com/aspnet_answers/NETFrameworkdrawing/Feb2006/post25815823.asp[^]
-
Ok, Only found VB.Net code: http://www.codeproject.com/vb/net/AlphaGradientPanel.asp[^] Martin
I saw that code... but I didn't understand it at all and I don't know how to convert it to C#. There are a lot of abilities in that thing that I don't need, and figuring out which line does what to extract the stuff I want requires VB knowledge that I just don't have. Not to mention the fact that I don't even know if that stuff even -has- a C# counterpart.
-M.
-
Hello, Have you tried changeing the Alpha Level of the BackColor. this.BackColor=Color.FromArgb(128,this.BackColor); All the best, Martin -- modified at 7:43 Wednesday 29th November, 2006 Have it from here. Tried it, but doesn't work????? http://www.eggheadcafe.com/aspnet_answers/NETFrameworkdrawing/Feb2006/post25815823.asp[^]
I have tried that, yeah, without success :-\
-M.
-
I don't understand... why should I create an entire form just to have a customized panel? I'm just looking for a a piece of code to stick in the OnPaint method of a custom panel that'll make it's background have opacity... I've seen it done in VB, but was unable to translate it to C#.
-M.
Something like this?
public partial class CustomPanel : Panel { Color color; public CustomPanel() { InitializeComponent(); color = Color.FromArgb(100, Color.Blue); } protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT return cp; } } protected override void OnPaintBackground(PaintEventArgs e){} protected override void OnPaint(PaintEventArgs e) { using (Brush brush = new SolidBrush(color)) { e.Graphics.Clear(Color.Transparent); e.Graphics.FillRectangle(brush, this.ClientRectangle); } } }
-
Something like this?
public partial class CustomPanel : Panel { Color color; public CustomPanel() { InitializeComponent(); color = Color.FromArgb(100, Color.Blue); } protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT return cp; } } protected override void OnPaintBackground(PaintEventArgs e){} protected override void OnPaint(PaintEventArgs e) { using (Brush brush = new SolidBrush(color)) { e.Graphics.Clear(Color.Transparent); e.Graphics.FillRectangle(brush, this.ClientRectangle); } } }
Yes! I've no idea why it works, but it does. Many thanks!
-M.