Windows Develop Bookmark and Share   
 index > Windows Forms General > Re size child form
 

Re size child form

Hi Experts

I have a MDI form1 that loads and fills the screen; I have a second form2 that is loaded as a child form2 has no title bar. I want form2 to load and fill the whole of the available space below form1’s menu strip. I don’t want the user to be able to re-size or close the form. If I set form2 to WindowState.Maximized an icon appears above form1, can I get rid? Is all this possible

Regards,

Joe

JoeBo  Saturday, July 28, 2007 7:26 AM

Dear Joe,

Check this link.

HTH,

Suprotim Agarwal

Suprotim Agarwal  Saturday, July 28, 2007 8:45 AM

Hi Joe,

You need to get the MdiClient container and then set the form2's sizeto the MdiClient's size. See my sample below.

MdiParent Form:

Code Snippet

MDIForm

public partial class SizeMainFrm : Form

{

public SizeMainFrm()

{

InitializeComponent();

}

System.Windows.Forms.MdiClient bgMDIClient;

private void openForm2ToolStripMenuItem_Click(object sender, EventArgs e)

{

SizeChildFrm frm = new SizeChildFrm();

frm.MdiParent = this;

frm.Show();

foreach (Control myControl in this.Controls)

{

if (myControl.GetType().ToString() == "System.Windows.Forms.MdiClient")

{

bgMDIClient = (System.Windows.Forms.MdiClient)myControl;

break;

}

}

if (bgMDIClient != null)

{

frm.Height = bgMDIClient.ClientSize.Height;

frm.Width = bgMDIClient.ClientSize.Width;

}

}

private void SizeMainFrm_Resize(object sender, EventArgs e)

{

if (bgMDIClient != null)

{

foreach (Form frm in this.MdiChildren)

{

if (frm.GetType() == typeof(SizeChildFrm))

{

frm.Height = bgMDIClient.ClientSize.Height;

frm.Width = bgMDIClient.ClientSize.Width;

}

}

}

}

}

Code Snippet

MDIForm

public partial class SizeChildFrm : Form

{

public SizeChildFrm()

{

InitializeComponent();

}

private void SizeChildFrm_Load(object sender, EventArgs e)

{

this.FormBorderStyle = FormBorderStyle.None;

this.ControlBox = false;

this.StartPosition = FormStartPosition.Manual;

this.Location = Point.Empty;

}

}

Dear Joe,

Check this link.

HTH,

Suprotim Agarwal

Suprotim Agarwal  Saturday, July 28, 2007 8:45 AM

Hi Joe,

You need to get the MdiClient container and then set the form2's sizeto the MdiClient's size. See my sample below.

MdiParent Form:

Code Snippet

MDIForm

public partial class SizeMainFrm : Form

{

public SizeMainFrm()

{

InitializeComponent();

}

System.Windows.Forms.MdiClient bgMDIClient;

private void openForm2ToolStripMenuItem_Click(object sender, EventArgs e)

{

SizeChildFrm frm = new SizeChildFrm();

frm.MdiParent = this;

frm.Show();

foreach (Control myControl in this.Controls)

{

if (myControl.GetType().ToString() == "System.Windows.Forms.MdiClient")

{

bgMDIClient = (System.Windows.Forms.MdiClient)myControl;

break;

}

}

if (bgMDIClient != null)

{

frm.Height = bgMDIClient.ClientSize.Height;

frm.Width = bgMDIClient.ClientSize.Width;

}

}

private void SizeMainFrm_Resize(object sender, EventArgs e)

{

if (bgMDIClient != null)

{

foreach (Form frm in this.MdiChildren)

{

if (frm.GetType() == typeof(SizeChildFrm))

{

frm.Height = bgMDIClient.ClientSize.Height;

frm.Width = bgMDIClient.ClientSize.Width;

}

}

}

}

}

Code Snippet

MDIForm

public partial class SizeChildFrm : Form

{

public SizeChildFrm()

{

InitializeComponent();

}

private void SizeChildFrm_Load(object sender, EventArgs e)

{

this.FormBorderStyle = FormBorderStyle.None;

this.ControlBox = false;

this.StartPosition = FormStartPosition.Manual;

this.Location = Point.Empty;

}

}

If you want to prevent the user from resizing, closing or maximizing an MDI child, there is no point in using MDI. Just use a regular form.

nobugz  Tuesday, July 31, 2007 11:08 AM

You can use google to search for other answers

Custom Search

More Threads

• populate Datagridview with randomly delimited space
• windows default border color
• Merging ToolStip toolbars
• How to select a line?
• Setting the Startup From
• Microsoft.AGL.Common.MISC.HandleAr() Exc
• Webbrowser1 document.click +vs2005
• Panel alpha transparency issues
• Is Label Text Ellipsed?
• How to use AutoScrollPosition when AutoScroll = false?