Hello guys. This simple example codes will open a single window. I have 2 ways of opening a window in MDI Form in C#.
1) Creating a Instance in a Form
2) Just create a variable of a Form
Example 1:
-Create a MDI Form and a Form1.
*At you Form1 write this codes:
private static Form1 sForm = null;
public static Form1 Instance()
{
if (sForm == null)
{ sForm = new Form1 (); }
return sForm;
}
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
sForm = null;
}
*In the MDI Form button for showing a Form1 write this codes:
Form sForm = new Form1.Instance();
sForm.MdiParent=this;
sForm.show();
sForm.Activate();
Example 2:
-Create a MDI Form and a Form1.
*Write this codes at your MDI Form:
//Create a variable:
private Form1 frm1 = new Form1();
//Button showing a Form1:
frm1.MdiParent=this;
frm1.show();
I hope this 2 ways of example can help you for those dont known on how to open a single window at C#.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment