可伸缩的Form窗体!

希望实现窗体的可折叠!像ArcToolBox中的窗体一下,点击显示帮助,窗体显示,点击收缩,窗体折叠。

窗体部件:

Panel控件,CheckBox控件

将Panel控件布置到窗体的右面,停靠

在FormLoad事件中输入下面代码:

 panel1.Visible = false;
 this.Width = this.Width - panel1.Width;

在checkBox的CheckedOnChange事件中输入下面代码:

private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            panel1.Visible = !panel1.Visible;
            if (panel1.Visible)
            {
                this.Width = this.Width + panel1.Width;
            }
            else
            {
                this.Width = this.Width - panel1.Width;
            }
        }

这样,窗体默认折叠,选择CheckBox1,窗体伸展。

文章未经说明均属原创,学习笔记可能有大段的引用,一般会注明参考文献。 欢迎大家留言交流,转载请注明出处。
原文地址:https://www.cnblogs.com/yhlx125/p/2455479.html