Hi, i am working on a little slot machine programme on c# and i need to create a totally transparent panel which is used to draw the winning payLines , but when i change the backColor to transparent this panel changed its color to grey( the back color of the form ) and i don't need that i need to show the picture box and the oldest panel bihind this new panel
Can i get an answer ?

You can only set the transparancy of the main window(your form)
Could you not show or hide your picturebox and oldest panel when needed?

Setting panel.BackColor = Color.Transparent does not work like you already noticed. The trick is to use transparency of the form as ddanbe hinted.

Here's two overlapping panels on a form. First one is a green square which is drawn behind the "transparent" panel. Second panel is the "transparent" panel. I set its BackColor to Red which will be the transparent color.

The last line sets form's TransparencyKey to Red color. This turns also the second panel transparent.

    // A green panel ("background panel") which gets behind the invisible panel
    panel2.Location = new System.Drawing.Point(50, 50);
    panel2.Size = new Size(100, 100);
    panel2.BackColor = Color.Green;
    panel2.ForeColor = Color.Black;
    panel2.Visible = true;
    MessageBox.Show("Press Ok to continue"); // Just to pause between steps

    // Invisible panel which covers the smaller green panel
    panel1.Location = new System.Drawing.Point(0, 0);
    panel1.Size = new Size(200, 200);
    panel1.BackColor = Color.Red; // Red is used as a "transparent" color
    panel1.ForeColor = Color.Black;
    panel1.Visible = true;
    MessageBox.Show("Press Ok to continue"); // Just to pause between steps

    // Set the *forms* TransparencyKey property to Red
    this.TransparencyKey = Color.Red;

HTH

For more flexibility, I would suggest WPF. There's a bit of a learning curve, but it allows you to have more options in transparency and animation.

commented: Obviously; WPF should be the best choice. +7

I would argue WPFs. They may seem like the best choice, but I should point out they aren't the greatest. They have practically no memory management. I had to write my own disposer pretty much to clean up a nasty memory leak. They are nice, but not always the best choice.

There is another way to do transpancy. You can actually draw on the form itself. I did this for an application once. You could also just draw the missing pieces behind, or have a new panel that you use something like "BringToFront"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.