Creating semi-transparent panels/controls. Is there a foolproof way?

.net, c#, custom-controls

Solution

I have done a few tests now.

You are mixiing several problems into one, so let's take them apart:

No WebBrowser is written in C# using Winforms. So this is no reason why this must be possible.

Your button almost certainly is not in the Form's Controls collection. You need to either script it to be or use a little UI trick (*) to place it over another Control without adding it to it.

When you scroll you will see whatever the scrolling control report as its surface.

Here are two screenshots:

This is after startup:

..and this is after I scrolled a little to the right:

I have use this code to make sure the Z-order is right:

button1.Parent = this;
panel1.BringToFront();
button1.BringToFront();
seeThroughPanel1.BringToFront();

Note how the the space of the button is spared; this shows how the old surface is being used.

To work around this you would have to get at the current Form surfacse (maybe by Control.DrawToBitmap) and then use the right part of that to paint your 'semi-transparent' panel. Of course it would have to hide before you capture the form's current surface.

Of all terrible ideas I have had, this seems to be one of the worst..

* The trick is to move it over the container with the keyboard, not the mouse; with this trick it just moves without chnging its parent container. Also useful for placing a Control on top of the tabs of a TabControl... But I was too lazy for that, so I coded it..

Problem

I am trying to create a semi-transparent control derived from `System.Windows.Forms.Panel`. [Edit: Basically what I want to achieve is this]: I have gone through numerous web articles as well as SO questions and have come up with this: ``` class SeeThroughPanel : Panel { public SeeThroughPanel() { } protected override CreateParams CreateParams { get { var cp = base.CreateParams; cp.ExStyle |= 0x00000020; return cp; } } protected override void OnPaint(PaintEventArgs e) { //base.OnPaint(e); e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(50, 0, 0, 0)), this.ClientRectangle); } } ``` Which results this (Note that this code too does not make it really semi-transparent. The button is displayed in full color, unlike in above image): However, as soon as I do something that causes repaint of any other controls within the bounds of the semi-transparent panel, it is overdrawn (In this case, I have scrolled the underlying control): So my question is, how can I avoid this? There has to be some way. After all, web browsers handle this kind of rendering all the time.

Original source