using winforms , mdi , parent and child form, opening child forms in specified space under the parent form

泄露秘密 提交于 2019-12-11 05:33:57

问题


I have a winform MAINFORM , and need to open child forms in this form as shown in the image. The black portion is a panel & would contain a no. of LinkLabels and Treeview with multiple nodes. In the rest of the portion i want to display the child forms when the linklabels on the panel would be clicked.

The child forms should exactly fit into the remaining space i.e. space excluding the space covered by the panel.

Please help me out with the code, how to fit the new form in the left space.

Also, i would like to ask, that, shall i use the panel or is there some other control which could be more efficient or better here. Also, does the MAINFORM needs to be made an MdiContainer?


回答1:


I'd have a user control interface on the right docked to fill the remaining space, and each time a link is clicked I'd populate the control interface with a specific control designed for that link labels content. That way you can forget about anything MDI related and for me at least, it would be a lot neater.

In a bit more detail, and a bit of a simpler way, basically everytime a link on the left is clicked, you create a user control that displays the relevant content for that link and display it on the right, docked to the main form so it fills the screen.

Then when another link is clicked, this control on the right is removed and the new one loaded. Have a read about creating user controls and see what you think about this method.

Here's a link to get you started: Creating and using Windows Forms Control Library (User Control) in C#.net

To split the form into sections, take a look at the Splitter control




回答2:


Winforms already does this automatically. You don't have to write any code, simply set the Dock property of the panel control to Left in the designer. The darkgray MDI client area automatically shrinks to occupy the remaining space. Any MDI child windows you create won't overlap the panel, they are constrained to the MDI client area.



来源:https://stackoverflow.com/questions/5472485/using-winforms-mdi-parent-and-child-form-opening-child-forms-in-specified-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!