private FormA formA = null;
private FormB formB = null;
private FormC formC = null;
private Form _curForm = null;
public Form1()
{
InitializeComponent();
formA = new FormA();
formA.MdiParent = this;
formA.Show();
formA.Closing += new System.ComponentModel.CancelEventHandler(this.MdiChild_Closing);
formB = new FormB();
formB.MdiParent = this;
formB.Show();
formB.Closing += new System.ComponentModel.CancelEventHandler(this.MdiChild_Closing);
formC = new FormC();
formC.MdiParent = this;
formC.Show();
formC.Closing += new System.ComponentModel.CancelEventHandler(this.MdiChild_Closing);
}
private void Form1_MdiChildActivate(object sender, EventArgs e)
{
if (_curForm != null)
{
if (_curForm is FormA)
{
((FormA) _curForm).ToolBar.Parent = null;
}
else if (_curForm is FormB)
{
((FormB) _curForm).ToolBar.Parent = null;
}
else if (_curForm is FormC)
{
((FormC) _curForm).ToolBar.Parent = null;
}
}
if (this.ActiveMdiChild is FormA)
{
_curForm = this.ActiveMdiChild;
((FormA)_curForm).ToolBar.Parent = panel3;
}
else if (this.ActiveMdiChild is FormB)
{
_curForm = this.ActiveMdiChild;
((FormB)_curForm).ToolBar.Parent = panel3;
}
else if (this.ActiveMdiChild is FormC)
{
_curForm = this.ActiveMdiChild;
((FormC)_curForm).ToolBar.Parent = panel3;
}
}
private bool _forceClose = false;
private void MdiChild_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if ( ! _forceClose )
{
((Form) sender).Hide();
e.Cancel = true;
}
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
_forceClose = true;
formA.Close();
formB.Close();
formC.Close();
e.Cancel = false;
}
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch (toolBar1.Buttons.IndexOf(e.Button))
{
case 0:
formA.Show();
formA.Activate();
break;
case 1:
formB.Show();
formB.Activate();
break;
case 2:
formC.Show();
formC.Activate();
break;
}
}
|