WinForm embedding, winform
1. Add two controls on the winform
1. Container> Panel
2. Add SideBar. dll (download link: http://pan.baidu.com/s/1o6qhf9w)
(1) Place SideBar. dll under SideBar control \ bin \ Debug
(2) drag SideBar. dll to the Toolbox> regular tab.
3. The implementation result is as follows:
Note: The left side of the form is the SideBar control and the right side is the Panel container.
Ii. Background code
(1) sidebartailload event sideBar1.AddGroup ("group name"); sideBar1.Groups [0]. items. add ("member name", 1); Note: 1 is a random write, no need to use this (2) sideBar1_ItemDoubleClick event Note: Click the name of the group member, if (e. item. text = "") {// re-paint Panel panel1.Controls. clear (); Form2 f2 = new Form2 (); // hide the subform border (remove the smallest flower, maximize, close, and other buttons) f2.FormBorderStyle = FormBorderStyle. none; // indicates that the child form is not a top-level form (Note: This is very important. If the child form is a top-level form, it cannot be embedded in the parent form) f2.TopLevel = false; // load the subform into panel this. panel1.Controls. add (f2); f2.Show ();}View Code
III,
4. End with source code: http://pan.baidu.com/s/1i3sZhbR
How to embed form forms (panel and subforms) in WinForm)
Today, I encountered a problem when working on the project. The form is divided into two parts: left and right. When you click the button on the left sidebar, the form is dynamically loaded on the right.
Finally, I tried to use panel to implement it. After several failures and searching for information, I finally got it done.
Note: If you need to add panel. clear () to perform multiple switchover, clear the original panel content.
Environment: C # VS2008
Method 1: attach sub-elements to the panel.
Form2 form =
New Form2 ();
Form. FormBorderStyle = FormBorderStyle. None; // hide the border of the subform (remove the smallest flower, maximize, close, and other buttons)
Form. TopLevel =
False; // indicates that the subform is not a top-level form.
This. panel1.Controls. Add (form); // load the subform into the panel.
Form. Show ();
Method 2: Specify the parent container implementation
Form2 form = new Form2 ();
Form. MdiParent = this; // specify the current form as the top-level Mdi form
Form. Parent = this. Panel1; // indicates that the Parent container of the child form is
Frm. FormBorderStyle = FormBorderStyle. None; // hide the subform border. Of course, this can also be implemented in the subform form loading event.
. NET. How can I embed a webpage in a winform?
Find the webbrowser control in the toolbox, drag it to the desired location, and set its url attribute.