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!
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.
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.
精彩评论