Hide/show part of the window with a button click
I have a simple form containing a main view and also some text boxes and an "add" button that I use for adding data that is displayed in the main view (and stored in a text file). What I want to do is to add a little button that will toggle hiding/showing of the adding controls. Such but开发者_如何学编程ton usually is a small square containing two arrowheads pointing up/down depending on the state. How do I do that?
(I'm sorry for the terrible title, but I don't know the proper name for this. Could anyone tell me?)
I don't think there's something built-in in WinForms for that. When I needed to do something similar, I just changed the Height of the form...
this.ClientSize = new System.Drawing.Size(required_width, required_height);
use a bool
for hiding/showing
You can use the forms Height
property and the controls could be hidden with Control.Visible = false
I think the word you're looking for is "Collapsible panel".
A quick google/codeproject search will provide you with some links:
- http://www.codeproject.com/KB/miscctrl/TgXPPanel.aspx
- http://www.codeproject.com/KB/miscctrl/XPCollapsGroupBox.aspx
- http://www.codeproject.com/KB/miscctrl/CollapsibleGroupBox.aspx
I suggest you use a SplitContainer control and play with the Panel2.Collapsed property by sitting it to true or false
put the control that you want to hide/show inside panel2 and put the button in panel1. Change the Orientation property to Vertical, and there you go
精彩评论