Open a single instance of a child form from the MDI Form

Ddd
Posted by Ddd under Windows Forms category on | Points: 40 | Views : 2859
1)Open a Windows Application

2)On the Form1 take a Menu Control. Design like this File-->Open

Set IsMdiConatiner=true for this form. Form1 is now the MDI Form.

3)Add another Windows Form Form2.


Form1.cs coding

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
internal static int i;
public Form1()
{
InitializeComponent();
}

private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
i++;
if (i <= 1)
{
Form2 f = new Form2();
f.MdiParent = this;
f.Show();
}

}
}
}

Form2.cs coding

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}


private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
Form1.i = 0;

}
}
}

Comments or Responses

Login to post response