160 likes | 174 Views
Learn to set up MDI interface with default styles, menu strips, tool strips, and manage multiple document windows effectively using C# programming language.
E N D
MDI介面建置 建國科技大學 資管系 饒瑞佶
預設MDI樣式 menustrip toolstrip 這裡面有些程式可以學 statusStrip
關閉所有表單 foreach (Form childForm in MdiChildren) { childForm.Close(); }
表單的排列 private void CascadeToolStripMenuItem_Click(object sender, EventArgs e) { LayoutMdi(MdiLayout.Cascade); } private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e) { LayoutMdi(MdiLayout.TileVertical); } private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e) { LayoutMdi(MdiLayout.TileHorizontal); } private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e) { LayoutMdi(MdiLayout.ArrangeIcons); }
開新視窗(未來開啟表單的方法) private int childFormNumber = 0; Form childForm = new Form(); childForm.MdiParent = this; childForm.Text = "視窗 " + childFormNumber++; childForm.Show();
開啟/另存檔案 private void OpenFile(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); openFileDialog.Filter = "文字檔 (*.txt)|*.txt|所有檔案 (*.*)|*.*"; if (openFileDialog.ShowDialog(this) == DialogResult.OK) { string FileName = openFileDialog.FileName; } } private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); saveFileDialog.Filter = "文字檔 (*.txt)|*.txt|所有檔案 (*.*)|*.*"; if (saveFileDialog.ShowDialog(this) == DialogResult.OK) { string FileName = saveFileDialog.FileName; } }
修改MDI 刪除所有物件,重新加入MenuStrip下拉選單物件
在MDI中顯示表單 //先宣告表單物件(全域變數) private 表單表單物件 = null; if (表單物件 == null ||表單物件.IsDisposed) { //判斷要開啟的視窗是否已經存在 表單物件 = new 表單(); 表單物件.MdiParent = this; 表單物件.Show(); } else { 表單物件.Activate(); // 跳到最前面一個視窗 }
重新加入toolstrip • 使用16 x 16大小的圖示(icon) • 透過Items設定選項與圖示
也可以直接在畫面上加入toolstrip上的物件 private void toolStripButton1_Click(object sender, EventArgs e) { MessageBox.Show(toolStripTextBox1.Text); }
重新加入statusStrip 竟然是toolStrip
試試toolStripProgressBar private void MDIParent1_Load(object sender, EventArgs e) { toolStripProgressBar1.Minimum = 0; toolStripProgressBar1.Maximum = 100; } private void timer1_Tick(object sender, EventArgs e) { toolStripProgressBar1.Value += 10; if(toolStripProgressBar1.Value == toolStripProgressBar1.Maximum) timer1.Enabled = false; }