简体   繁体   中英

WinForms: How do I make a collapsible UI region on the form, like Visual Studio's toolbox?

I want to add a collapse/expand capability to a Windows Form.

Is this built into the splitter control? Is there a tutorial for this UI technique?

The immediate project I'm thinking of is a simple UI, Windows Forms. It has 3 panels, one oriented at the top, one in the middle and one at the bottom. I want to be able to collapse the middle panel completely, but yet keep it available for expansion.


I saw the SO question,
Looking for a Visual Studio toolbox style navigation for desktop applications

..and that's more about a toolbox with draggable components . I don't care about the draggable capability. What I want is a collapsible form region, the way the toolbox and other elements in VS are collapsible, the way the IE8 favorites panel is pinnable or collapsible.

I'd use a FlowLayoutPanel .

It will do exactly what you describe.

Add 3 panels to it. In the 2nd panel, add another FlowLayoutPanel. Inside that one, add a label and YourCollapsablePanel. When clicking the label, toggle the visibility of the panel below it.

If you mean for it to collapse like the Toolbox does in visual studio then the DockPanelSuite will do that for you. You can turn off the ability to drag and dock the windows elsewhere.

use System.Windows.Forms.SplitContainer

inside the SplitContainer panel you can use a FlowLayoutPanel or a custom toolbox

Define a FlowLayout panel and add your panels to that and structure them to your needs.

In your middle panel add a small contol button with an image of collapse to begin with. In the click event set the visibility to false, flip the image to expand button and vice versa .

[Edited. Flow layout will make things easier]

你看过DockPanel套件了吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM