将groupbox设置为不可见或在其上生成阴影c#

将groupbox设置为不可见或在其上生成阴影c#,c#,winforms,C#,Winforms,我试图了解windowsforms中的GroupBox是如何工作的。我现在的问题是。我有两个分组框,每个都有两个单选按钮。例如,我希望当点击groupbox1中的radiobutton 2时,整个groupbox2是不可见的,或者最好在其上放置一个白色阴影,不允许用户使用它。我在这里读过,但没发现什么。我尝试了属性可见,但使整个窗口不可见。下面是我的示例代码。提前谢谢 using System; using System.Collections.Generic; using System.Com

我试图了解windowsforms中的GroupBox是如何工作的。我现在的问题是。我有两个分组框,每个都有两个单选按钮。例如,我希望当点击groupbox1中的radiobutton 2时,整个groupbox2是不可见的,或者最好在其上放置一个白色阴影,不允许用户使用它。我在这里读过,但没发现什么。我尝试了属性可见,但使整个窗口不可见。下面是我的示例代码。提前谢谢

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace groupbox
{
   public partial class Form1 : Form
  {
    public Form1()
    {
        InitializeComponent();
        radioButton1.Checked = true;
        radioButton3.Checked = true;
    }

    private void groupBox1_Enter(object sender, EventArgs e)
    {
        if (radioButton4.Checked == true) {
            this.Visible = false;
        }
    }

    private void groupBox2_Enter(object sender, EventArgs e)
    {
        if (radioButton2.Checked == true)
        {
            this.Visible = false;
        }
       }
  }
  } 

我也读过这篇文章,但是没有面板的话还有吗?

这篇文章是指代码所在的类,在本例中是指表单


您应该尝试
groupBox1.Visible=false
groupBox1.Enabled=false

指的是代码所在的类—在本例中为表单

您应该尝试
groupBox1.Visible=false
groupBox1.Enabled=false

尝试以下操作:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        radioButton1.Checked = true;
        radioButton3.Checked = true;
        radioButton2.CheckedChanged += radioButton2_CheckedChanged;
    }

    void radioButton2_CheckedChanged(object sender, EventArgs e)
    {
        groupBox2.Enabled = !radioButton2.Checked;
    }
}
试试这个:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        radioButton1.Checked = true;
        radioButton3.Checked = true;
        radioButton2.CheckedChanged += radioButton2_CheckedChanged;
    }

    void radioButton2_CheckedChanged(object sender, EventArgs e)
    {
        groupBox2.Enabled = !radioButton2.Checked;
    }
}

此方法中的
指的是您的窗口(WinForms中的“表单”)。这就是为什么您的整个窗口变得不可见,而不仅仅是组框。您是否尝试过类似于
groupBox1.Visible=false?谢谢。我认为这会起作用。非常感谢
此方法中的
指的是您的窗口(WinForms中的“表单”)。这就是为什么您的整个窗口变得不可见,而不仅仅是组框。您是否尝试过类似于
groupBox1.Visible=false?谢谢。我认为这会起作用。谢谢!非常感谢。我认为这会起作用。谢谢!非常感谢。我认为这会起作用。谢谢!非常感谢,这正是我想要的。不是完全看不见,而是有阴影在上面。非常感谢,这正是我想要的。不是完全看不见,而是有一个影子在上面。