it’s another time there is some asking about how to show form into another form. i have been trying to find around the web to get the example . but i found the answer myself as following example. . . [try to understand my bad English] . ha ha
in this posting i will show how to put existing two form into one main form , by the way i’m doing this in main form i put the tab with two tab pages , first tabpage for first form and anther tab put second form. as following picture.

figure 1. show two tab in main form
By doing this i create the project with main form name form1.cs and another two is anotherform.cs and moreform.cs
First – put two tab into mainform (form1.cs) and place panel1 into tabpage1 and groupbox1 into tabpage2 [please note this the control must be a container control]
then – Create another two form , anotherform.cs and moreform.cs
anotherform.cs

figure 2. show anotherform.cs
in this form show information of two textbox when you click ‘show information’ button
moreform.cs

figure 3. show moreform.cs
in this form the textbox will show the selected text of above combobox…
I will not go in detail of how these two form work i will explain how it work in the main form.
in main form (form1.cs) , see the following code, better then explain…
01 | public void ShowFormInControl(Control myctl, Form myfrm) |
04 | myfrm.TopLevel = false ; |
05 | myfrm.FormBorderStyle = FormBorderStyle.None; |
06 | myfrm.Dock = DockStyle.Fill; |
08 | myctl.Controls.Add(myfrm); |
12 | private void button1_Click( object sender, EventArgs e) |
14 | anotherForm myform = new anotherForm(); |
15 | ShowFormInControl(panel1, myform); |
17 | moreForm myform2 = new moreForm(); |
18 | ShowFormInControl(groupBox1, myform2); |
in the source code you can see the technique of how to put the form into control in the “ShowformInControl(Control myctl, Form myfrm) “ the function perform putting the form ( myfrm ) into Control( myctl ) as i mention earlier – the control must be container control. without any explanation it’s obviously show in the code…
then the forms are load by the click event of button1. – create form and put into control by calling ShowformInControl where ever you want to put , panel or groupbox or any contrainer control.
ref : http://gpluspluss.com/2010/07/24/how-to-embed-a-form-in-a-control-%E0%B8%88%E0%B8%B1%E0%B8%9A-from-%E0%B8%A1%E0%B8%B2%E0%B9%83%E0%B8%AA%E0%B9%88-form/
No comments:
Post a Comment