launch a form from within another

  • Thread starter Thread starter Tammy
  • Start date Start date
T

Tammy

How do I launch a form from within another?
The book I have only talks about MDI forms and I know that there should be a
way to do that
without the MDI form.
 
Just create an instance of the form and show it;

eg: Form is called myForm.

MyForm myform2 = new MyForm();

myform2.Show();

or

myform2.ShowDialog();


-p
 
I was posting this question for a student.

The student is not asking how to load a from from another form. But, how to
load a form "inside" of another form. Not using MIDI. (The parent form
becomes the child form frame.)
 
You mean that the new form should be displayed inside the current form and
the current one shouldn't be an MDI one ? If so, I think you have to use
SetParent win32api. I don't think it would be directly possible in dotnet. I
don't see a use for it either.

Yves
 
Tammy,

You will have to use the SetWindow API which is declared using C#
like this

public class Win32
{
private Win32()
{
}

[DllImport("user32.dll", SetLastError=true)]
public static extern IntPtr SetParent(
IntPtr childWindow, IntPtr newParent);
}

You would then use it like this (from inside a form) if you forexamples
wanted to open a form called ChildForm

ChildForm c = new ChildForm();
Win32.SetParent(c.Handle, this.Handle);
c.Show();

HTH,

//Andreas
 
Phoeniz,

There is a good use for it and it is to host remote windows in your
own window for seamless integration. For example a plugin could provide
it's own configuration page which could be integrated into your applications
settings form. I do this in my extensibility framework and it is a very nice
way
to integrate functionality.

HTH,

//Andreas
 
// Play around with this format for a while and you'll find some intriguing
possibilities:

Form2 f2 = new Form2();
f2.TopLevel = false;
f2.Location = new Point( 100, 100 );
f2.FormBorderStyle = FormBorderStyle.None;
f2.BackColor = SystemColors.ControlDark;
this.Controls.Add( f2 );
f2.Show();

Chris A.R.
 
Back
Top