代码之家  ›  专栏  ›  技术社区  ›  aleroot

将扩展器(折叠/展开)添加到面板窗体

  •  25
  • aleroot  · 技术社区  · 14 年前

    有人做过类似的事吗?

    5 回复  |  直到 11 年前
        1
  •  13
  •   Olivier Jacot-Descombes    8 年前
        2
  •  42
  •   Bradley Smith    14 年前

    这个 SplitContainer 控件可以折叠其两个面板中的一个。你可以在门上扣个钮扣 Panel1Collapsed

        3
  •  20
  •   Community CDub    4 年前

    看看我的WinFormExpander控件- https://github.com/alexander-makarov/ExpandCollapsePanel

    一般来说,它必须满足这种控制的所有基本要求。

    • 在窗体设计器中轻松编辑
    • 将所需的任何控件放入内容区域
    • 应用不同的样式和大小

    Easy editing in Form Designer

        4
  •  6
  •   noelicus    11 年前

    使用 SplitContainer 折叠是指:

    Visible 属性来显示/隐藏它。这样,当空间不可见时,其他停靠的项目将移动以填充空间(取决于它们的位置) Dock

    例如,如果隐藏面板时按钮、面板和标签都固定在顶部(按该顺序),则标签将上移到按钮下方。

        5
  •  0
  •   Hi-Angel    7 年前

    我没法工作 (不记得细节了,但我遇到了麻烦) ,所以今天我直接用这个函数手动完成了。要折叠控件,请传递一个否定参数作为\u sz。

        /// <summary>
        /// (In|De)creases a height of the «control» and the window «form», and moves accordingly
        /// down or up elements in the «move_list». To decrease size pass a negative argument
        /// to «the_sz».
        /// Usually used to collapse (or expand) elements of a form, and to move controls of the
        /// «move_list» down to fill the appeared gap.
        /// </summary>
        /// <param name="control">control to collapse/expand</param>
        /// <param name="form">form to get resized accordingly after the size of a control
        /// changed (pass «null» if you don't want to)</param>
        /// <param name="move_list">A list of controls that should also be moved up or down to
        /// «the_sz» size (e.g. to fill a gap after the «control» collapsed)</param>
        /// <param name="the_sz">size to change the control, form, and the «move_list»</param>
        public static void ToggleControlY(Control control, Form form, List<Control> move_list, int the_sz)
        {
            //→ Change sz of ctrl
            control.Height += the_sz;
            //→ Change sz of Wind
            if (form != null)
                form.Height += the_sz;
            //*** We leaved a gap(or intersected with another controls) now!
            //→ So, move up/down a list of a controls
            foreach (Control ctrl in move_list)
            {
                Point loc = ctrl.Location;
                loc.Y += the_sz;
                ctrl.Location = loc;
            }
        }
    

    我只是在groupBox上添加了一个标签,并将这个函数添加到标签的onClick事件中。为了让用户更清楚地了解扩展能力,我在文本的开头添加了字符 ⇘ .