共用方式為


Menu 類別

定義

警告

Menu is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use ToolStripDropDown and ToolStripDropDownMenu instead.

代表所有選單的基本功能。

此課程在 .NET Core 3.1 及更新版本中無法使用。 使用ToolStripDropDownToolStripDropDownMenu取代並擴展控制。Menu

public ref class Menu abstract : System::ComponentModel::Component
[System.ComponentModel.ListBindable(false)]
public abstract class Menu : System.ComponentModel.Component
[System.ComponentModel.ListBindable(false)]
[System.ComponentModel.Browsable(false)]
[System.Obsolete("`Menu` is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use `ToolStripDropDown` and `ToolStripDropDownMenu` instead.", false, DiagnosticId="WFDEV006", UrlFormat="https://aka.ms/winforms-warnings/{0}")]
public abstract class Menu : System.ComponentModel.Component
[<System.ComponentModel.ListBindable(false)>]
type Menu = class
    inherit Component
[<System.ComponentModel.ListBindable(false)>]
[<System.ComponentModel.Browsable(false)>]
[<System.Obsolete("`Menu` is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use `ToolStripDropDown` and `ToolStripDropDownMenu` instead.", false, DiagnosticId="WFDEV006", UrlFormat="https://aka.ms/winforms-warnings/{0}")>]
type Menu = class
    inherit Component
Public MustInherit Class Menu
Inherits Component
繼承
衍生
屬性

範例

以下程式碼範例使用派生類別 MenuItem,來建立表單的選單結構。 範例程式碼會新增 a MenuItem 來表示頂層選單項目,加入一個子選單項目用於選擇字型大小,然後在該選單項目中加入兩個子選單項目,分別代表應用程式中的大字型與小字型選擇。 範例要求有一個 MainMenu 名為 mainMenu1 的物件,以及四個 MenuItem 名為 menuItem1menuItem2menuItem3menuItem4的物件。

public:
   void CreateMyMenu()
   {
      // Set the caption for the top-level menu item.
      menuItem1->Text = "Edit";
      // Set the caption for the first submenu.
      menuItem2->Text = "Font Size";
      // Set the caption for menuItem2's first submenu.
      menuItem3->Text = "Small";
      // Set the checked property to true since this is the default value.
      menuItem3->Checked = true;
      // Define a shortcut key combination for the menu item.
      menuItem3->Shortcut = Shortcut::CtrlS;
      // Set the caption of the second sub menu item of menuItem2.
      menuItem4->Text = "Large";
      // Define a shortcut key combination for the menu item.
      menuItem4->Shortcut = Shortcut::CtrlL;
      // Set the index of the menu item so it is placed below the first submenu item.
      menuItem4->Index = 1;
      // Add menuItem3 and menuItem4 to menuItem2's list of menu items.
      menuItem2->MenuItems->Add( menuItem3 );
      menuItem2->MenuItems->Add( menuItem4 );
      // Add menuItem2 to menuItem1's list of menu items.
      menuItem1->MenuItems->Add( menuItem2 );
      // Add menuItem1 to the MainMenu for displaying.
      mainMenu1->MenuItems->Add( menuItem1 );
   }
public void CreateMyMenu()
    {
    // Set the caption for the top-level menu item.
    menuItem1.Text = "Edit";
    // Set the caption for the first submenu.
    menuItem2.Text = "Font Size";
    // Set the caption for menuItem2's first submenu.
    menuItem3.Text = "Small";
    // Set the checked property to true since this is the default value.
    menuItem3.Checked = true;
    // Define a shortcut key combination for the menu item.
    menuItem3.Shortcut = Shortcut.CtrlS;
    // Set the caption of the second sub menu item of menuItem2.
    menuItem4.Text = "Large";
    // Define a shortcut key combination for the menu item.
    menuItem4.Shortcut = Shortcut.CtrlL;
    // Set the index of the menu item so it is placed below the first submenu item.
    menuItem4.Index = 1;
    // Add menuItem3 and menuItem4 to menuItem2's list of menu items.
    menuItem2.MenuItems.Add(menuItem3);
    menuItem2.MenuItems.Add(menuItem4);
    // Add menuItem2 to menuItem1's list of menu items.
    menuItem1.MenuItems.Add(menuItem2);
    // Add menuItem1 to the MainMenu for displaying.
    mainMenu1.MenuItems.Add(menuItem1);
    }
Public Sub CreateMyMenu()
    ' Set the caption for the top-level menu item.
    menuItem1.Text = "Edit"
    ' Set the caption for the first submenu.
    menuItem2.Text = "Font Size"
    ' Set the caption for menuItem2's first submenu.
    menuItem3.Text = "Small"
    ' Set the checked property to true since this is the default value.
    menuItem3.Checked = True
    ' Define a shortcut key combination for the menu item.
    menuItem3.Shortcut = Shortcut.CtrlS
    ' Set the caption of the second sub menu item of menuItem2.
    menuItem4.Text = "Large"
    ' Define a shortcut key combination for the menu item.
    menuItem4.Shortcut = Shortcut.CtrlL
    ' Set the index of the menu item so it is placed below the first submenu item.
    menuItem4.Index = 1
    ' Add menuItem3 and menuItem4 to menuItem2's list of menu items.
    menuItem2.MenuItems.Add(menuItem3)
    menuItem2.MenuItems.Add(menuItem4)
    ' Add menuItem2 to menuItem1's list of menu items.
    menuItem1.MenuItems.Add(menuItem2)
    ' Add menuItem1 to the MainMenu for displaying.
    mainMenu1.MenuItems.Add(menuItem1)
End Sub

備註

此課程在 .NET Core 3.1 及更新版本中無法使用。 請改用 ToolStripDropDownToolStripDropDownMenu

此類別是 、 、 MainMenuMenuItem 類別的基底類別ContextMenu。 你無法建立這個類別的實例。 應用程式的選單由 MenuItem 物件組成。 這些物件可以包含其他 MenuItem 物件,代表子選單項目。 這些 MenuItem 物件可以儲存 MainMenu 在一個中,作為完整的選單結構,作為表單或用來顯示捷徑選單的結構 ContextMenu 。 此類別提供所有選單類別共有的功能。

與許多基底類別不同,該 Menu 類別使用其衍生類別來定義許多屬性。 如果你在多文件介面(MDI)應用程式中使用選單,你可以使用屬性 MdiListItem 指定 a MenuItem ,顯示應用程式中已開啟的 MDI 子表單清單。 該 MenuItems 屬性包含一份儲存在選單類別中的物件清單 MenuItem 。 對於 MainMenuContextMenu,此性質包含所有 MenuItem 顯示的物件。 對於 MenuItem,屬性 MenuItems 代表與之相關的子選單項目。

除了所有衍生選單類別所提供的屬性外,該 Menu 類別還提供方法, CloneMenu 例如和 MergeMenu,讓你能從現有選單建立新選單,並合併兩個選單結構。

Menu 類別也定義了巢狀類別 Menu.MenuItemCollection。 此類別定義了該MenuItems屬性所使用的物件集合MenuItem。 你可以利用類別 Menu.MenuItemCollection 的方法來新增或移除選單項目, MainMenu從 、 ContextMenuMenuItem

建構函式

名稱 Description
Menu(MenuItem[])
已淘汰.

初始化 Menu 類別的新執行個體。

欄位

名稱 Description
FindHandle
已淘汰.

指定 FindMenuItem(Int32, IntPtr) 方法應搜尋一個句柄。

FindShortcut
已淘汰.

指定 FindMenuItem(Int32, IntPtr) 方法應該搜尋捷徑。

屬性

名稱 Description
CanRaiseEvents
已淘汰.

會得到一個值,表示該元件是否能引發事件。

(繼承來源 Component)
Container
已淘汰.

得到 IContainer 包含 Component的 。

(繼承來源 Component)
DesignMode
已淘汰.

會得到一個值,表示目前 Component 是否處於設計模式。

(繼承來源 Component)
Events
已淘汰.

會取得與此 Component連結的事件處理程序清單。

(繼承來源 Component)
Handle
已淘汰.

會得到一個代表選單視窗柄的值。

IsParent
已淘汰.

會有一個值,表示此菜單是否包含任何菜單項目。 這個屬性是唯讀的。

MdiListItem
已淘汰.

會獲得一個值,表示 , MenuItem 用來顯示多文件介面(MDI)子表單的清單。

MenuItems
已淘汰.

會獲得一個值,表示與選單相關的物件集合 MenuItem

Name
已淘汰.

取得或設定 的名稱。Menu

Site
已淘汰.

取得或設定 ISiteComponent

(繼承來源 Component)
Tag
已淘汰.

取得或設定與控制項相關的使用者定義資料。

方法

名稱 Description
CloneMenu(Menu)
已淘汰.

複製 Menu 該參數傳遞給當前 Menu

CreateMenuHandle()
已淘汰.

建立一個新的 handle 到 Menu

CreateObjRef(Type)
已淘汰.

建立一個物件,包含產生代理伺服器所需的所有相關資訊,用於與遠端物件通訊。

(繼承來源 MarshalByRefObject)
Dispose()
已淘汰.

釋放所有由 Component.

(繼承來源 Component)
Dispose(Boolean)
已淘汰.

處理除記憶體外,所使用的 Menu資源。

Equals(Object)
已淘汰.

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
FindMenuItem(Int32, IntPtr)
已淘汰.

取得 MenuItem 包含指定值的 。

FindMergePosition(Int32)
已淘汰.

回傳選單項目應插入選單的位置。

GetContextMenu()
已淘汰.

ContextMenu 到包含這個選單的那個。

GetHashCode()
已淘汰.

做為預設哈希函式。

(繼承來源 Object)
GetLifetimeService()
已淘汰.

取得目前控制此實例生命週期政策的終身服務物件。

(繼承來源 MarshalByRefObject)
GetMainMenu()
已淘汰.

MainMenu 到包含這個選單的那個。

GetService(Type)
已淘汰.

回傳一個由 或Component其 所提供的Container服務的物件。

(繼承來源 Component)
GetType()
已淘汰.

取得目前實例的 Type

(繼承來源 Object)
InitializeLifetimeService()
已淘汰.

取得一個終身服務物件以控制此實例的終身政策。

(繼承來源 MarshalByRefObject)
MemberwiseClone()
已淘汰.

建立目前 Object的淺層複本。

(繼承來源 Object)
MemberwiseClone(Boolean)
已淘汰.

建立一個 MarshalByRefObject 目前物件的淺層複製品。

(繼承來源 MarshalByRefObject)
MergeMenu(Menu)
已淘汰.

MenuItem 一個選單的物件與目前選單合併。

ProcessCmdKey(Message, Keys)
已淘汰.

處理指令鍵。

ToString()
已淘汰.

回傳代表控制的 Menu aString

事件

名稱 Description
Disposed
已淘汰.

當元件被呼叫方法 Dispose() 時會發生。

(繼承來源 Component)

適用於

另請參閱