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.
|