1

I have a transparent form which has panels and buttons. How do I make my panel x%(i.e. 50%, 60%, 75%) transparent. I know that could be done by decreasing or increasing the Opacity, but since my form is transparent(with Transparency Key) the panel's color fades and becomes white as I decrease the Opacity.

I have gone through many sites but every site tells how to make the form fully transparent or about its opacity.

I want to do this with my panel not a form. All I want is to make my panel look like a blue mirror or like a hologram(2D).

I have a WinForms application with .NET 5.0 core.

[NOTE: This question might seem similar but I didn't understand the answers of it]

NoNAME
  • 65
  • 8
  • @DocBrown While researching...I also checked this, but I didn't understand the answers – NoNAME Apr 24 '21 at 11:19
  • 2
    Your best bet then is to go through the answers you don't understand, one by one, and ask their authors about what you do not understand in their particular answer. – Doc Brown Apr 24 '21 at 11:29
  • 1
    Or, alternatively to the suggestion from @Doc, post a question that actually references the answer or answers you're trying to understand. Make sure you include a proper [mcve], along with a detailed explanation of what you tried, what the code does, how that's different from what you want, and what _specifically_ you need help with. – Peter Duniho Apr 24 '21 at 17:38

1 Answers1

2

There's a trick which you can do. Follow the stpes to execute it

  1. Instead of the panel, place a child form at the same location
frmChild.Location = new Point(x, y); //x and y are variables for which you can give the value anything
  1. Give it the controls which you were going to give to the panel(like buttons, labels etc)

  2. Set the child form's opacity to x%.
    form2.Opacity = .75;

To know in a detailed way how to set the opacity of the child form you can visit this website or this video

And to place a child form in the main form you can do this -

private Form activeForm = null;
private void showChldForm(Form ChldForm, int x, int y) {
    if(activeForm != null)
        activeForm.Close();
    activeForm = ChldForm;
    ChldForm.TopLevel = false;
    ChldForm.FormBorderStyle = FormBorderStyle.None;
    Form1.Controls.Add(ChldForm);
    ChldForm.Location = new Point(x, y); //You can set the child form's location here
    ChldForm.Show();
}

You can call this method when a button is clicked if you want the form to appear when a button is clicked or if you want to make the form visible at the start, call this method in the constructor

By following the code if you get any errors you can have a look at this video or you can ask me in the comments

Naitik
  • 55
  • 1
  • 8