設置當子窗體的的大小小於主窗體時,自動調整大小
設置當子窗體的的大小小於主窗體時,自動調整大小
//soctt 20070827 窗體大小改變事件
this.SizeChanged += new EventHandler(FMzMain_SizeChanged);
/// <summary>
/// soctt 200070827
/// 使子窗體自動調整
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void FMzMain_SizeChanged(object sender, EventArgs e)
{
//判斷是否有子窗體及窗體狀態變成正常
if (this.MdiChildren.Length > 0 && this.WindowState== FormWindowState.Normal)
{
//定議窗體數量的變量
int iCurrMdiNumber = 1;
//設置窗體的初始位置
Point ptLocation = new Point(0, 0);
foreach (Form fmChild in this.MdiChildren)
{
//判斷是否是活動子窗體
if (fmChild == this.ActiveMdiChild)
{
//當為活動窗體時,位置為(0,0)
ptLocation = new Point(0, 0);
//fmChild.Location = this.CenterToParent;
}
else
{
//變更子窗體的位置
ptLocation.X = iCurrMdiNumber*25;
ptLocation.Y= iCurrMdiNumber*25;
}
//判斷窗體的寬度是否小於主窗體
//ClientSize:取得表單工作區大小
if (fmChild.Size.Width >= this.ClientSize.Width-10 && fmChild.Size.Height <=this.ClientSize.Height- 80)
{
//設置窗體的位置
fmChild.Location = ptLocation;
//變更窗體的大小
fmChild.Size = new Size(this.ClientSize.Width - 10, fmChild.Size.Height);
//變更變量,用於改變窗體位置
iCurrMdiNumber++;
}
//判斷窗體的高度是否小於主窗體的高度
if (fmChild.Size.Height >= this.ClientSize.Height - 80 && fmChild.Size.Width <= this.ClientSize.Width - 10)
{
fmChild.Location = ptLocation;
fmChild.Size = new Size(fmChild.Size.Width, this.ClientSize.Height - 80);
iCurrMdiNumber++;
}
//判斷窗體的高度,寬度是否都小於主窗體
if (fmChild.Size.Width >= this.ClientSize.Width - 10 && fmChild.Size.Height >= this.ClientSize.Height - 80)
{
fmChild.Location = ptLocation;
fmChild.Size = new Size(this.ClientSize.Width - 10, this.ClientSize.Height - 80);
//fmChild.Size = new Size(this.Size.Width - 30, fmChild.Size.Height - 125);
iCurrMdiNumber++;
}
//設置子窗體最小大小
fmChild.MinimumSize = new Size(550, 400);
}
}
}
this.SizeChanged += new EventHandler(FMzMain_SizeChanged);
/// <summary>
/// soctt 200070827
/// 使子窗體自動調整
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void FMzMain_SizeChanged(object sender, EventArgs e)
{
//判斷是否有子窗體及窗體狀態變成正常
if (this.MdiChildren.Length > 0 && this.WindowState== FormWindowState.Normal)
{
//定議窗體數量的變量
int iCurrMdiNumber = 1;
//設置窗體的初始位置
Point ptLocation = new Point(0, 0);
foreach (Form fmChild in this.MdiChildren)
{
//判斷是否是活動子窗體
if (fmChild == this.ActiveMdiChild)
{
//當為活動窗體時,位置為(0,0)
ptLocation = new Point(0, 0);
//fmChild.Location = this.CenterToParent;
}
else
{
//變更子窗體的位置
ptLocation.X = iCurrMdiNumber*25;
ptLocation.Y= iCurrMdiNumber*25;
}
//判斷窗體的寬度是否小於主窗體
//ClientSize:取得表單工作區大小
if (fmChild.Size.Width >= this.ClientSize.Width-10 && fmChild.Size.Height <=this.ClientSize.Height- 80)
{
//設置窗體的位置
fmChild.Location = ptLocation;
//變更窗體的大小
fmChild.Size = new Size(this.ClientSize.Width - 10, fmChild.Size.Height);
//變更變量,用於改變窗體位置
iCurrMdiNumber++;
}
//判斷窗體的高度是否小於主窗體的高度
if (fmChild.Size.Height >= this.ClientSize.Height - 80 && fmChild.Size.Width <= this.ClientSize.Width - 10)
{
fmChild.Location = ptLocation;
fmChild.Size = new Size(fmChild.Size.Width, this.ClientSize.Height - 80);
iCurrMdiNumber++;
}
//判斷窗體的高度,寬度是否都小於主窗體
if (fmChild.Size.Width >= this.ClientSize.Width - 10 && fmChild.Size.Height >= this.ClientSize.Height - 80)
{
fmChild.Location = ptLocation;
fmChild.Size = new Size(this.ClientSize.Width - 10, this.ClientSize.Height - 80);
//fmChild.Size = new Size(this.Size.Width - 30, fmChild.Size.Height - 125);
iCurrMdiNumber++;
}
//設置子窗體最小大小
fmChild.MinimumSize = new Size(550, 400);
}
}
}