0

How to transparent a panel in vb.net? the default color of the panel is white

Private Sub frm_console_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'Panel1.BackColor = Color.Transparent //i've tried this too
     Panel1.BackColor = Color.FromArgb(25, Color.Black)

End Sub

Click image

jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
May Yie
  • 87
  • 1
  • 9
  • WinForms doesn't support transparency like that. You can fake full transparency but partial transparency is not supported. If that's what you want, use WPF. It was created from the ground up to support modern features like transparency. – jmcilhinney Jun 17 '21 at 02:32
  • how can i fake full transparency? – May Yie Jun 17 '21 at 02:35
  • It appears that I was wrong. I just tried setting the `BackColor` of a `Panel` to a partially transparent colour and it worked perfectly. I did pretty much just what you did and it worked as expected/desired. Try these steps. Create a new WinForms project and set the `BackgroundImage` property of the form. Add three `Panels` to the form and set the `BaclColor` to `Red`, `Red` and `Transparent` respectively. In the `Load` event handler add `Panel2.BackColor = Color.FromArgb(100, Panel2.BackColor)`. You should see full red, transparent red and complete transparency in the three `Panels`. – jmcilhinney Jun 17 '21 at 02:43
  • Just note that this is still not "real" transparency. What happens is the control draws its parent in its background so it appears transparent. If you put another control behind the transparent one though, you will not see it but will still see the parent. That's what I mean by "fake transparency". – jmcilhinney Jun 17 '21 at 02:45
  • [Transparent image over two controls with different back colors](https://stackoverflow.com/a/54261539/7444103) <- this uses exactly a Panel, makes it transparent to overlap other Controls (plural). Or, if you want to make it a little more complex: [Translucent circular Control with text](https://stackoverflow.com/a/51435842/7444103): C#, but you can make a Custom Control and use it in VB.Net, if you don't speak the language. -- You can overlap any other Control on a Form, transparency is preserved. You only need to avoid overlapping scrollable controls. Unless you tweak it a little bit more. – Jimi Jun 17 '21 at 03:18

1 Answers1

1

I didn't originally look at your screenshot but now I see that your problem is exactly what I was talking about, i.e. WinForms doesn't support real transparency. It supports "fake" transparency in that a control with a transparent BackColor will draw its parent in its own background to make it appear that you can see through it. It only draws the parent though, so any sibling controls that are partially obscured, e.g. the Buttons in your screenshot, will not show through.

There's nothing you can do about that because that's just the way WinForms works. If you want real transparency like that then you'll need to use WPF instead, which was built from the ground up to support modern features like transparency.

jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
  • do i have to send it back? – May Yie Jun 17 '21 at 03:04
  • @MayYie, if you want to send the `Panel` to the back of the z-order then go ahead, but that is nothing to do with transparency. Read my lips: Windows Forms DOES NOT support transparency. It doesn't matter how much you want it or how many questions you ask. WinForms STILL doesn't support transparency. If you want transparency then stop using WinForms and use WPF instead. If you want to stick with WinForms then you need to give up on transparency beyond the fake transparency that WinForms actually supports. – jmcilhinney Jun 17 '21 at 03:09