Incorrect location of forms in MDI application

  • Thread starter sirish csv via .NET 247
  • Start date
S

sirish csv via .NET 247

Hi,
I have an MDI application. Initially I open say 5 forms, theyposition themselves in a cascaded manner. When I close all ofthem and open another form it positions itself in the locationwhich would have come after the 5th form. It is as if the MDIparent is remembering the locations of the previously openedforms and positioning the new accordingly.
Ideally if all forms are closed and a new one is opened it shouldopen at the Top left corner of the MDI parent window.
Could someone tell me what can be done to ensure that forms opennormally one after the other(other than callingLayoutMDI.Cascade() as this would cascade even maximisedforms)So that the new form is consistent with the already openedforms if present.
This behavior can be observed in a simple example with 1 MDIparent and a child form opened from menu.Open 5 times and closeall forms and open again.

Thanks in advance.
Regards
Sirish

/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem6;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponentcall
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(newSystem.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(newSystem.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem6});
this.menuItem1.Text = "Foems";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "Forms1";
this.menuItem2.Click += newSystem.EventHandler(this.menuItem2_Click);
//
// menuItem6
//
this.menuItem6.Index = 1;
this.menuItem6.Text = "Form3";
this.menuItem6.Click += newSystem.EventHandler(this.menuItem6_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.IsMdiContainer = true;
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Form1";

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

Form2 frm;
private void menuItem2_Click(object sender, System.EventArgse)
{
frm= new Form2();
frm.MdiParent = this;
frm.Show();
}

private void menuItem6_Click(object sender, System.EventArgse)
{
Form3 frm1 = new Form3();
frm1.MdiParent = this;
frm1.Show();
}
}
 
A

Axel Dahmen

The behaviour you perceive is the standard Windows MDI behaviour. If you
want to implement your own, you will have to manually write your own window
manager code, wading through all open MDI child forms and calculate the
position you like.

If you do so, you should also consider what should happen if the user only
closes the third of five forms or perhaps only the first of five or....

HTH,
Axel Dahmen
www.sportbootcharter.com


---------------
Hi,
I have an MDI application. Initially I open say 5 forms, they position
themselves in a cascaded manner. When I close all of them and open another
form it positions itself in the location which would have come after the 5th
form. It is as if the MDI parent is remembering the locations of the
previously opened forms and positioning the new accordingly.
Ideally if all forms are closed and a new one is opened it should open at
the Top left corner of the MDI parent window.
Could someone tell me what can be done to ensure that forms open normally
one after the other(other than calling LayoutMDI.Cascade() as this would
cascade even maximised forms)So that the new form is consistent with the
already opened forms if present.
This behavior can be observed in a simple example with 1 MDI parent and a
child form opened from menu.Open 5 times and close all forms and open again.

Thanks in advance.
Regards
Sirish

/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem6;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem6});
this.menuItem1.Text = "Foems";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "Forms1";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem6
//
this.menuItem6.Index = 1;
this.menuItem6.Text = "Form3";
this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.IsMdiContainer = true;
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Form1";

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

Form2 frm;
private void menuItem2_Click(object sender, System.EventArgs e)
{
frm= new Form2();
frm.MdiParent = this;
frm.Show();
}

private void menuItem6_Click(object sender, System.EventArgs e)
{
Form3 frm1 = new Form3();
frm1.MdiParent = this;
frm1.Show();
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top