如何:使用 MenuStrip 建立 MDI 視窗清單 (Windows Form)

使用多文檔介面 (MDI) 來建立應用程式,以同時開啟數份檔,並將內容從一份檔案複製並貼到另一份檔。

此程式示範如何在父視窗功能表上建立所有使用中子表單的清單。

在 MenuStrip 上建立 MDI 視窗清單

  1. 建立表單,並將其 IsMdiContainer 屬性設定為 true

  2. MenuStrip 加入表單。

  3. 將兩個最上層功能表項目新增至 , MenuStrip 並將其屬性設定 Text&File&Window

  4. 將兩個子功能表項目目新增至 &File 功能表項目,並將其屬性設定 Text&Open&New

  5. MdiWindowListItem 的 屬性設定為 &WindowToolStripMenuItemMenuStrip

  6. 將表單新增至專案,並新增您想要的控制項,例如另一個 MenuStrip

  7. &NewToolStripMenuItemClick 事件建立事件處理常式。

  8. 在事件處理常式中,插入類似下列的程式碼,以建立並顯示 的新實例做為 的 Form1 MDI 子系 Form2

    Private Sub openToolStripMenuItem_Click(ByVal sender As _  
    System.Object, ByVal e As System.EventArgs) Handles _  
    openToolStripMenuItem.Click  
        Dim NewMDIChild As New Form2()  
        'Set the parent form of the child window.  
            NewMDIChild.MdiParent = Me  
        'Display the new form.  
            NewMDIChild.Show()  
    End Sub  
    
    private void newToolStripMenuItem_Click(object sender, EventArgs e)  
    {  
        Form2 newMDIChild = new Form2();  
        // Set the parent form of the child window.  
            newMDIChild.MdiParent = this;  
        // Display the new form.  
            newMDIChild.Show();  
    }  
    

編譯程式碼

這個範例需要:

另請參閱