[英]Expand/Collapse Win Form in C#
I want to create UI like this in Windows form application C#. 我想在Windows窗体应用程序C#中创建这样的UI。 First my form should appear like this when the chechBox is not checked. 首先,当未选中chechBox时,我的表单应如下所示。
And if the checkBox checked my form changes to like this 如果checkBox检查了我的表单,则更改为这样
How can I do this? 我怎样才能做到这一点?
Change the height of the form dynamically on CheckedChanged
event of check box. 在复选框的CheckedChanged
事件中动态更改表单的高度。 Don't forget to set anchor of below fields or set visible on expand and invisible on collapse. 不要忘记在下面的字段设置锚点,或者在展开时设置为可见,而在折叠时设置为不可见。
EDIT: The most simple way to achieve the results is given below. 编辑:实现结果的最简单方法如下。
private readonly int _collapsedHeight;
public Form1()
{
//Set Anchor of Connect button to Right and Bottom and leave default for others
//Optionally you need to hide controls except Connect button on collapse and vice versa.
//Set Form Border Style to FixedSingle and MaximizeBox to false
InitializeComponent();
_collapsedHeight = Height;
}
private void chkAdvancedOption_CheckedChanged(object sender, EventArgs e)
{
//Set Y value to collapse eg. 140, adjust it as required...
Height = chkAdvancedOption.Checked ? _collapsedHeight + 140 : _collapsedHeight;
}
void Page_Load(Object sender, EventArgs e)
{
// Manually register the event-handling method for the
// CheckedChanged event of the CheckBox control.
checkbox1.CheckedChanged += new EventHandler(this.Check_Clicked);
}
void Check_Clicked(Object sender, EventArgs e)
{
**//This is only sample code**
// do your code
if (panel2.Visible)
{
panel2.Visible = false;
cmdAdvanced.Visible = true;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.