VB Like c# MDI APPLICATION

Posted: April 24, 2005 in Uncategorized

Today i was asked  from a vb developer who recently  moves into c# how he can design a mdi application in c# which have same functionality as like vb.The problem was the instance and how to display it like the vb functionality.Luckily to debug soem old code i d installed vb and i craete a sampel vb app to study the mdi functionality he was talking about.Also i search the web and many people have impelmented many complicated flag set to achieve the same and further some are setting null to form and checking the same and many stuff.

I have design the same very simple code :-before giving the code let me write i have a mdi in which i have placed file menu and 4 submenu under it for 3 child and one close and heer is the code to set the mdi app

I know my vb friends are missing the default form and the forms collection badly.however soon ms is thinking of giving you ur old form collectiona nd default form..howveer until then here is the code you can do ur bit..

[STAThread]

static void Main()

{

Application.Run(

new frmMDI());

}

private bool isexist(string frmname)

{ foreach(Form frmcol in this.MdiChildren)

{

if (frmcol.Text ==frmname)

{

frmcol.BringToFront();

return true;

}

}

return false;

}

private void position(Form frm)

{ frm.Left=this.Left;

frm.Top =this.Top ;

frm.Width =this.Width-10;

frm.Height =this.Height-10;

}

private void menuItem1_Click(object sender, System.EventArgs e)

{

if (isexist("Form1")==false )

{ Form frm=new Form1 ();

frm.MdiParent =this;

position(frm);

frm.Show();

}

}

private void menuItem2_Click(object sender, System.EventArgs e)

{

if (isexist("Form2")==false )

{ Form frm=new Form2 ();

frm.MdiParent =this;

position(frm);

frm.Show();

}

}

private void menuItem3_Click(object sender, System.EventArgs e)

{

if (isexist("Form3")==false )

{ Form frm=new Form3 ();

frm.MdiParent =this;

position(frm);

frm.Show();

}

}

private void menuItem5_Click(object sender, System.EventArgs e)

{

this.Close();

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s