Creating child window
-
Assuming your child form is called Form2, and this code is being called from another form:
Form2 form2 = new Form2(); form2.Parent = this; // form2 is now a child of this form // show form 2
Or, if Form2 is to be displayed as a dialog box:Form2 form2 = new Form2(this) // show form 2
-
Assuming your child form is called Form2, and this code is being called from another form:
Form2 form2 = new Form2(); form2.Parent = this; // form2 is now a child of this form // show form 2
Or, if Form2 is to be displayed as a dialog box:Form2 form2 = new Form2(this) // show form 2
Well, method 1 gives me:
An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll
Additional information: Cannot add a top level control to a control.
And neither my own form nor the System.Windows.Forms.Form class has a (Form) constructor...
-
Well, method 1 gives me:
An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll
Additional information: Cannot add a top level control to a control.
And neither my own form nor the System.Windows.Forms.Form class has a (Form) constructor...
Set the new Form's TopLevel property to false before you make it Visible or Show() it.
-
Set the new Form's TopLevel property to false before you make it Visible or Show() it.
Thanks! That worked. However, the window is created with the WS_CHILD style, which makes it be "inside" the main window. This I do not want. How can I make it not use the WS_CHILD style, but still have the main window as its parent? I don't see any place to specify the window styles manually...
-
Thanks! That worked. However, the window is created with the WS_CHILD style, which makes it be "inside" the main window. This I do not want. How can I make it not use the WS_CHILD style, but still have the main window as its parent? I don't see any place to specify the window styles manually...
Hmm, also try
TopMost = true;
in addition toTopLevel = false;