Windows Develop Bookmark and Share   
 index > Windows Forms General > Prevent cascading/offset in MDI Child Form
 

Prevent cascading/offset in MDI Child Form

Hi Experts,

I am coming across a very weird problem while developing an MDI-based Windows Application on VS2008.

I have an MDI Form with menu bars and all. As Child Form I only have one form at a time. This is because, the Child form is not a document but a form with data entry fields.

Now when I open a child form for the first time, it is displayed okay. But when I close it and open it again, it's location automatically changes to a little up higher. Something like cascading is happening to the form I believe.
The weird part it, this cascading or offset effect occurs every alternate time the child form is opened!

I do follow the location and other properties, I shud give in this case:

ChildForm1.FormBorderStyle = None;
ChildForm1.StartPosition = Manual;
ChildForm1.WindowState = Maximized;

//before showing:
ChildForm1.Left = 0;
ChildForm1.Top = 0;
ChildForm1.Height = this.Height - myOffsetY;
ChildForm1.Width = this.Width - myOffsetX;
ChildForm1.Show();


Any suggestions or work around are greatly appreciated!

Thanks!
If the reply answers your question, please mark it as Answer, or Helpful, if it helped! Thanks!
BA_Newbie  Wednesday, October 07, 2009 9:58 AM
Hey all,

I solved it using the following trick:

In the ChildForm, I added an event handler for the Resize event and re-sized my form back to its original shape:


private void ChildForm1_Resize(object sender, EventArgs e)
{
           //RestoreBounds Property contains the original shape
           this.SetBounds(this.RestoreBounds.X, this.RestoreBounds.Y, this.RestoreBounds.Width, this.RestoreBounds.Height);
           this.Refresh();
}

In case, anyone else is also looking for the solution....



If the reply answers your question, please mark it as Answer, or Helpful, if it helped! Thanks!
  • Marked As Answer byBA_Newbie Wednesday, October 07, 2009 11:54 AM
  •  
BA_Newbie  Wednesday, October 07, 2009 11:53 AM
Hey all,

I solved it using the following trick:

In the ChildForm, I added an event handler for the Resize event and re-sized my form back to its original shape:


private void ChildForm1_Resize(object sender, EventArgs e)
{
           //RestoreBounds Property contains the original shape
           this.SetBounds(this.RestoreBounds.X, this.RestoreBounds.Y, this.RestoreBounds.Width, this.RestoreBounds.Height);
           this.Refresh();
}

In case, anyone else is also looking for the solution....



If the reply answers your question, please mark it as Answer, or Helpful, if it helped! Thanks!
  • Marked As Answer byBA_Newbie Wednesday, October 07, 2009 11:54 AM
  •  
BA_Newbie  Wednesday, October 07, 2009 11:53 AM

You can use google to search for other answers

Custom Search

More Threads

• .Net 2.0 - WebBrowser control embedded in IE causes problems
• trouble resizing a panel at runtime
• ListView SelectedIndexChanged
• How can I get IP address ?
• Dynamic Sql inside of stored procedure
• how to set up an exit handler exactly like what atexit() does?
• Theoretical Question for advanced programmers
• resize of user control within user control within form
• XML -> XSD -> DataSet -> Data Source
• Save form as JPEG format.