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

后端 未结 2 1410
谎友^
谎友^ 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:24

    Crate a C# project and add 3 forms named

    1. MAIN
    2. BACKGOUND
    3. Child

    and add the following code for "MAIN" form load event;

    private void MAIN_Load(object sender, EventArgs e)
    {
         Child frm1 = new  Child();
         BACKGOUND frm2 = new BACKGOUND();
         frm2 .WindowState = System.Windows.Forms.FormWindowState.Maximized;      
    
         frm2.Opacity = 0.5;
         frm2.Show();
    
         frm1.ShowDialog();
         frm2.Close();
    }
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题