This post is for MDI Parent child relation in windows application.
the code detects whether child form is already opened or not.
If already opened then it did not allow to create a new child and reopens (maximise) the existed form.
here is the code for that
on click event of menu
private void toolStripMenuItem5_Click( object sender, EventArgs e)
{
// to check whether form is opened
if (!CheckExistingForm(" VanMaster"))
{
VanMaster vanMaster = new VanMaster(this);
vanMaster.Show();
}
}
the code detects whether child form is already opened or not.
If already opened then it did not allow to create a new child and reopens (maximise) the existed form.
here is the code for that
on click event of menu
private void toolStripMenuItem5_Click(
{
// to check whether form is opened
if (!CheckExistingForm("
{
VanMaster vanMaster = new VanMaster(this);
vanMaster.Show();
}
}
******************************
// method to check if propvided form is exists or open before
// method to check if propvided form is exists or open before
{
int flag = 0;
Form[] forms = this.MdiChildren;
if (forms.Length > 0)
{
for (int i = 0; i < forms.Length; i++)
{
if (forms[i].Name == formName)
{
forms[i].WindowState = FormWindowState.Normal;
flag = 1;
break;
}
}
if (flag == 1)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
**********************************************************8
at VanMaster.cs file
public partial class VanMaster : Form
{
public VanMaster(Form Parent)
{
InitializeComponent();
this.Parent = Parent;
}
}
No comments:
Post a Comment