Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I have semi transparent panel written in c# for .net 4.0
it work fine on Windows XP,Vista,7 but it doesn't work fine on Windows 8, 8.1.
On Windows 8 and 8.1 the panel is not semitransparent.
Is there anyone who can tell me why?

Here is my code

C#
public class MyPanel : System.Windows.Forms.Panel
{
    public MyPanel() : base()
    {
        this.SetStyle(ControlStyles.UserPaint, true);
        this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        this.SetStyle(ControlStyles.ResizeRedraw, true);
        this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
        this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
    }

    protected override CreateParams CreateParams
    {
        get
        {
            var cp = base.CreateParams;
            cp.ExStyle |= 0x00000020;
            return cp;
        }
    }

    protected override void OnPaintBackground(PaintEventArgs e)
    {
        // Do not paint background.
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);

        e.Graphics.Clear(System.Drawing.Color.White);
        e.Graphics.CopyFromScreen(this.PointToScreen(new Point(0, 0)), new Point(0, 0), new Size(this.Width, this.Height));
        e.Graphics.FillRectangle(new SolidBrush(System.Drawing.Color.FromArgb(120, System.Drawing.Color.Gray)), new Rectangle(new Point(0, 0), this.Size));
    }
}
Posted

Transparency doesn't exist in Win 8...

But you can use this utility to work in the background[^]
 
Share this answer
 
Since it seems that you are using WinForms, you could use Opacity member of the form to set transparency.

I have done semi-transparent stuff but essentially, I use two forms so that only one part is semi-transparent. I then synchronize moving and activation so to the end user it appears as a single form have a semi-transparent area inside it.

The opaque form probably uses a color key for fully transparent area where the other form is located. The second form is created without border.

If I remeber well, for the activation I need to access the API as I want the main form to appears as activate when the user click on the semi-transparent form.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900