Winforms布局:展开/折叠部分UI

mar*_*que 0 c# layout winforms

第一件事:不可能使用WPF,因为它是一个插件(对于SolidWorks)而一个用于WPF的ElementHost会导致显示错误.

我需要使ui元素相对.这意味着,如果我隐藏一些元素,我希望下面的元素缩小差距.

我尝试使用锚点和growandshrink/autosize面板 - 没有运气.

示例UI:

[Button]
[*] Checked RadioButton
       [TextField]
       [AnotherTextField]
[ ] Unchecked RadioButton
[Button]
Run Code Online (Sandbox Code Playgroud)

更改选定的RadioButton后,第二个RadioButton和所有后续元素应该关闭间隙,如下所示:

[Button]
[ ] Unchecked RadioButton
[*] Checked RadioButton
[Button]
Run Code Online (Sandbox Code Playgroud)

Han*_*ant 5

这对于FlowLayoutPanel来说是微不足道的.将Flow属性设置为TopDown.添加一个RadioButton,两个TextBox和另一个RadioButton.在TextBoxes上设置Margin属性,使它们看起来缩进(例如Left = 20),它们的Visible属性为False.

然后你只需要一小段代码就可以使它们的Visible属性跟随单选按钮的Checked属性:

    private void radioButton1_CheckedChanged(object sender, EventArgs e) {
        textBox1.Visible = textBox2.Visible = radioButton1.Checked;
    }
Run Code Online (Sandbox Code Playgroud)