how to exclude control from a WinForm.Opacity in C#

后端 未结 2 1411
谎友^
谎友^ 2021-01-20 07:48

I have a form that i set it\'s Opacity as 50% like this:

this.Opacity = 0.5D; <--this==Form

My problem is that everything that on the fo

2条回答
  •  孤城傲影
    2021-01-20 08:30

    Since Control doesn't have Opacity property and plus that, most of the controls doesn't support transparent colors, then a working solution can be this:

    1. Create a Form called MainForm and place all the controls you're going to be excluded.

      1.1 Set both of BackColor and TransparencyKey properties of MainForm to the same color, e.g Color.Red

    2. Create another form named TransparentForm and place all controls that must become transparent. Set ShowInTaskbar property to False.

    3. In the MainForm Load event show the TransparentForm and send it to back.

      private void MainForm_Load(object sender, EventArgs e)
      {
          TransparentForm form = new TransparentForm();
          form.Opacity = 0.5D;
          form.Show();
          form.SendToBack(); 
      }
      

      enter image description here

    The position of controls in both form must be such that, when combined, it shows the proper user interface.

提交回复
热议问题