views:

593

answers:

2

Hi there, im trying to create a semi-transparent form which is displayed in a panel. i can display the form in the panel but the opacity property wont work and the form is non-transparent.

private void button1_Click(object sender, EventArgs e)
{
      Form fr = new Form();
      fr.FormBorderStyle = FormBorderStyle.None;
      fr.BackColor = Color.Black;
      fr.TopLevel = false;
      fr.Opacity = 0.5;
      this.panel1.Controls.Add(fr);
      fr.Show();
}

any ideas how i can handle that? Thanks for your answeres!

A: 

Your form is added as a child control of panel1 which is child of the main form which is of default Opacity = 1.

To see Opacity at work, try this:

private void button1_Click(object sender, EventArgs e)
{
    Form fr = new Form();
    fr.FormBorderStyle = FormBorderStyle.None;
    fr.BackColor = Color.Blue;
    fr.TopLevel = false;
    //fr.Opacity = 0.5;
    this.Opacity = 0.5; // add this
    this.panel1.Controls.Add(fr);
    fr.Show();
}

I guess you want the panel to look semi-transparent, you have to use another method and work with the form itself.

o.k.w
+2  A: 

Winforms only supports partial transparency for top-level forms. If you want to create an application with partially-transparent UI elements, you either need to use WPF, or handle all the drawing yourself. Sorry to be the bearer of bad news.

Simon
The truth hurts sometimes :P
o.k.w