29 Ocak 2011 Cumartesi

Show a Form in Another Form - mdi Forms

Hello friends,

In this article, we will find out how to put a form into another form. As you know, when developing a desktop application, we mostly use more than one form. That means we should show them in one frame, because otherwise it does not seem good quite often.

After explanation, let's see the codes.

There are two forms in our project, named as ParentForm and ChildForm. There are two ways to generate ParentForm, one of them is generating a normal windows form and set its mdiParent property in its constructor, other one is that generating a mdi parent form.





In this example, we choose the first way. Here is our parent form,



                                                                       Parent Form

Now, let's see the codes which are written into ParentForm.cs;


public partial class ParentForm : Form
{
public ParentForm()
{

this.IsMdiContainer = true; //This makes ParentForm a MdiContainer.
InitializeComponent();
ChildForm child = new ChildForm(); //New ChildFOrm object
child.MdiParent = this; //Sets ParentForm as parent of ChildForm
child.Dock = DockStyle.Fill; //Sets Dock property
child.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; //Removes the frame of //ChildForm
child.Show; //Shows ChildForm
}
}

Here is the result;


See you in another article !

Hiç yorum yok:

Yorum Gönder