MDIウィンドウの例です。
ウィンドウの中に子ウィンドウが入れ子になっています。
MDIウィンドウを作るには
親にしたいFormのIsMdiContainerプロパティーにtrueを設定するだけです。
子ウィンドウ側は
MdiParentプロパティーに親ウィンドウのインスタンスを設定します。
後はShow()するだけです。
例ではForm1を親ウィンドウ、Form2を子ウィンドウとし、
Form1のメニューより【開く】を選択すると子ウィンドウが表示されます。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { System.Diagnostics.PerformanceCounter pc = new System.Diagnostics.PerformanceCounter(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // MDI親ウィンドウにする this.IsMdiContainer = true; } private void 開くToolStripMenuItem_Click(object sender, EventArgs e) { // MDI子ウィンドウを開く Form2 form = new Form2(); form.MdiParent = this; // 親を指定 form.Text = "新しいForm:" + this.MdiChildren.Length.ToString(); form.Show(); } } }
コメントを残す