FormABC.cs
----------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace ChangeToolbar2003
{
/// <summary>
/// Form1 の概要の説明です。
/// </summary>
public class FormABC : System.Windows.Forms.Form
{
private System.Windows.Forms.ToolBar toolBarA;
private System.Windows.Forms.ToolBarButton toolBarButtonA1;
private System.Windows.Forms.ToolBarButton toolBarButtonA2;
private System.Windows.Forms.ToolBarButton toolBarButtonA3;
private System.Windows.Forms.ToolBar toolBarB;
private System.Windows.Forms.ToolBar toolBarC;
private System.Windows.Forms.ToolBarButton toolBarButtonB1;
private System.Windows.Forms.ToolBarButton toolBarButtonB2;
private System.Windows.Forms.ToolBarButton toolBarButtonB3;
private System.Windows.Forms.ToolBarButton toolBarButtonC1;
private System.Windows.Forms.ToolBarButton toolBarButtonC2;
private System.Windows.Forms.ToolBarButton toolBarButtonC3;
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
private System.ComponentModel.Container components = null;
public FormABC()
{
//
// Windows フォーム デザイナ サポートに必要です。
//
InitializeComponent();
//
// TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。
//
}
/// <summary>
/// 使用されているリソースに後処理を実行します。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows フォーム デザイナで生成されたコード
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
private void InitializeComponent()
{
this.toolBarA = new System.Windows.Forms.ToolBar();
this.toolBarButtonA1 = new System.Windows.Forms.ToolBarButton();
this.toolBarButtonA2 = new System.Windows.Forms.ToolBarButton();
this.toolBarButtonA3 = new System.Windows.Forms.ToolBarButton();
this.toolBarB = new System.Windows.Forms.ToolBar();
this.toolBarC = new System.Windows.Forms.ToolBar();
this.toolBarButtonB1 = new System.Windows.Forms.ToolBarButton();
this.toolBarButtonB2 = new System.Windows.Forms.ToolBarButton();
this.toolBarButtonB3 = new System.Windows.Forms.ToolBarButton();
this.toolBarButtonC1 = new System.Windows.Forms.ToolBarButton();
this.toolBarButtonC2 = new System.Windows.Forms.ToolBarButton();
this.toolBarButtonC3 = new System.Windows.Forms.ToolBarButton();
this.SuspendLayout();
//
// toolBarA
//
this.toolBarA.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarButtonA1,
this.toolBarButtonA2,
this.toolBarButtonA3});
this.toolBarA.DropDownArrows = true;
this.toolBarA.Location = new System.Drawing.Point(0, 0);
this.toolBarA.Name = "toolBarA";
this.toolBarA.ShowToolTips = true;
this.toolBarA.Size = new System.Drawing.Size(608, 41);
this.toolBarA.TabIndex = 1;
this.toolBarA.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBarA_ButtonClick);
//
// toolBarButtonA1
//
this.toolBarButtonA1.Text = "A1";
//
// toolBarButtonA2
//
this.toolBarButtonA2.Text = "A2";
//
// toolBarButtonA3
//
this.toolBarButtonA3.Text = "A3";
//
// toolBarB
//
this.toolBarB.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarButtonB1,
this.toolBarButtonB2,
this.toolBarButtonB3});
this.toolBarB.DropDownArrows = true;
this.toolBarB.Location = new System.Drawing.Point(0, 41);
this.toolBarB.Name = "toolBarB";
this.toolBarB.ShowToolTips = true;
this.toolBarB.Size = new System.Drawing.Size(608, 41);
this.toolBarB.TabIndex = 3;
this.toolBarB.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBarB_ButtonClick);
//
// toolBarC
//
this.toolBarC.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarButtonC1,
this.toolBarButtonC2,
this.toolBarButtonC3});
this.toolBarC.DropDownArrows = true;
this.toolBarC.Location = new System.Drawing.Point(0, 82);
this.toolBarC.Name = "toolBarC";
this.toolBarC.ShowToolTips = true;
this.toolBarC.Size = new System.Drawing.Size(608, 41);
this.toolBarC.TabIndex = 4;
this.toolBarC.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBarC_ButtonClick);
//
// toolBarButtonB1
//
this.toolBarButtonB1.Text = "B1";
//
// toolBarButtonB2
//
this.toolBarButtonB2.Text = "B2";
//
// toolBarButtonB3
//
this.toolBarButtonB3.Text = "B3";
//
// toolBarButtonC1
//
this.toolBarButtonC1.Text = "C1";
//
// toolBarButtonC2
//
this.toolBarButtonC2.Text = "C2";
//
// toolBarButtonC3
//
this.toolBarButtonC3.Text = "C3";
//
// FormABC
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
this.ClientSize = new System.Drawing.Size(608, 374);
this.Controls.Add(this.toolBarC);
this.Controls.Add(this.toolBarB);
this.Controls.Add(this.toolBarA);
this.IsMdiContainer = true;
this.Name = "FormABC";
this.Text = "FormABC";
this.Load += new System.EventHandler(this.FormABC_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// アプリケーションのメイン エントリ ポイントです。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new FormABC());
}
private void toolBarA_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch (toolBarA.Buttons.IndexOf(e.Button))
{
case 0:
this.ShowFormA();
frmA.Activate();
break;
case 1:
this.ShowFormB();
frmB.Activate();
break;
case 2:
this.ShowFormC();
frmC.Activate();
break;
}
}
private void toolBarB_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch (toolBarB.Buttons.IndexOf(e.Button))
{
case 0:
this.ShowFormA();
frmA.Activate();
break;
case 1:
this.ShowFormB();
frmB.Activate();
break;
case 2:
this.ShowFormC();
frmC.Activate();
break;
}
}
private void toolBarC_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch (toolBarC.Buttons.IndexOf(e.Button))
{
case 0:
this.ShowFormA();
frmA.Activate();
break;
case 1:
this.ShowFormB();
frmB.Activate();
break;
case 2:
this.ShowFormC();
frmC.Activate();
break;
}
}
FormA frmA = null;
FormB frmB = null;
FormC frmC = null;
private void FormABC_Load(object sender, System.EventArgs e)
{
toolBarA.Visible = false;
toolBarB.Visible = false;
toolBarC.Visible = false;
ShowFormA();
ShowFormB();
ShowFormC();
}
private void ShowFormA()
{
if (frmA == null)
{
frmA = new FormA();
frmA.MdiParent = this;
}
frmA.Show();
}
private void ShowFormB()
{
if (frmB == null)
{
frmB = new FormB();
frmB.MdiParent = this;
}
frmB.Show();
}
private void ShowFormC()
{
if (frmC == null)
{
frmC = new FormC();
frmC.MdiParent = this;
}
frmC.Show();
}
public void SetTheToolbar(Form frm)
{
SuspendLayout();
if (frm is FormA)
{
this.toolBarA.Visible = true;
this.toolBarB.Visible = false;
this.toolBarC.Visible = false;
}
else if (frm is FormB)
{
this.toolBarA.Visible = false;
this.toolBarB.Visible = true;
this.toolBarC.Visible = false;
}
else if (frm is FormC)
{
this.toolBarA.Visible = false;
this.toolBarB.Visible = false;
this.toolBarC.Visible = true;
}
ResumeLayout();
}
}
}
FormA.cs
--------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace ChangeToolbar2003
{
/// <summary>
/// FormA の概要の説明です。
/// </summary>
public class FormA : System.Windows.Forms.Form
{
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
private System.ComponentModel.Container components = null;
public FormA()
{
//
// Windows フォーム デザイナ サポートに必要です。
//
InitializeComponent();
//
// TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。
//
}
/// <summary>
/// 使用されているリソースに後処理を実行します。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows フォーム デザイナで生成されたコード
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
private void InitializeComponent()
{
//
// FormA
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "FormA";
this.Text = "FormA";
this.Closing += new System.ComponentModel.CancelEventHandler(this.FormA_Closing);
this.Activated += new System.EventHandler(this.FormA_Activated);
}
#endregion
private void FormA_Activated(object sender, System.EventArgs e)
{
((FormABC)MdiParent).SetTheToolbar(this);
}
private void FormA_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
Hide();
}
}
}
|