ToolStripDropDownMenu クラス
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _ <ComVisibleAttribute(True)> _ Public Class ToolStripDropDownMenu Inherits ToolStripDropDown
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] [ComVisibleAttribute(true)] public class ToolStripDropDownMenu : ToolStripDropDown
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] [ComVisibleAttribute(true)] public ref class ToolStripDropDownMenu : public ToolStripDropDown
ToolStripDropDownMenu は、ContextMenuStrip の基本クラスで、描画とレイアウトに関する必要なプロパティとメソッドを用意します。このクラスのプロパティのうち、直接使用する可能性が最も高いものは、ShowCheckMargin プロパティと ShowImageMargin プロパティです。これらは、ショートカット メニューにチェック マーク、イメージ、またはその両方を表示できるかどうかを決定します。
チェック マークとイメージのマージンを設定して、ContextMenuStrip コントロールを作成および初期化する方法を次のコード例に示します。完全なコードの一覧については、「方法 : ContextMenuStrip コントロールでチェックの余白とイメージの余白を有効にする」を参照してください。
Public Sub New() ' Size the form to show three wide menu items. Me.Width = 500 Me.Text = "ToolStripContextMenuStrip: Image and Check Margins" ' Create a new MenuStrip control. Dim ms As New MenuStrip() ' Create the ToolStripMenuItems for the MenuStrip control. Dim bothMargins As New ToolStripMenuItem("BothMargins") Dim imageMarginOnly As New ToolStripMenuItem("ImageMargin") Dim checkMarginOnly As New ToolStripMenuItem("CheckMargin") Dim noMargins As New ToolStripMenuItem("NoMargins") ' Customize the DropDowns menus. ' This ToolStripMenuItem has an image margin ' and a check margin. bothMargins.DropDown = CreateCheckImageContextMenuStrip() CType(bothMargins.DropDown, ContextMenuStrip).ShowImageMargin = True CType(bothMargins.DropDown, ContextMenuStrip).ShowCheckMargin = True ' This ToolStripMenuItem has only an image margin. imageMarginOnly.DropDown = CreateCheckImageContextMenuStrip() CType(imageMarginOnly.DropDown, ContextMenuStrip).ShowImageMargin = True CType(imageMarginOnly.DropDown, ContextMenuStrip).ShowCheckMargin = False ' This ToolStripMenuItem has only a check margin. checkMarginOnly.DropDown = CreateCheckImageContextMenuStrip() CType(checkMarginOnly.DropDown, ContextMenuStrip).ShowImageMargin = False CType(checkMarginOnly.DropDown, ContextMenuStrip).ShowCheckMargin = True ' This ToolStripMenuItem has no image and no check margin. noMargins.DropDown = CreateCheckImageContextMenuStrip() CType(noMargins.DropDown, ContextMenuStrip).ShowImageMargin = False CType(noMargins.DropDown, ContextMenuStrip).ShowCheckMargin = False ' Populate the MenuStrip control with the ToolStripMenuItems. ms.Items.Add(bothMargins) ms.Items.Add(imageMarginOnly) ms.Items.Add(checkMarginOnly) ms.Items.Add(noMargins) ' Dock the MenuStrip control to the top of the form. ms.Dock = DockStyle.Top ' Add the MenuStrip control to the controls collection last. ' This is important for correct placement in the z-order. Me.Controls.Add(ms) End Sub
public Form5() { // Size the form to show three wide menu items. this.Width = 500; this.Text = "ToolStripContextMenuStrip: Image and Check Margins"; // Create a new MenuStrip control. MenuStrip ms = new MenuStrip(); // Create the ToolStripMenuItems for the MenuStrip control. ToolStripMenuItem bothMargins = new ToolStripMenuItem("BothMargins"); ToolStripMenuItem imageMarginOnly = new ToolStripMenuItem("ImageMargin"); ToolStripMenuItem checkMarginOnly = new ToolStripMenuItem("CheckMargin"); ToolStripMenuItem noMargins = new ToolStripMenuItem("NoMargins"); // Customize the DropDowns menus. // This ToolStripMenuItem has an image margin // and a check margin. bothMargins.DropDown = CreateCheckImageContextMenuStrip(); ((ContextMenuStrip)bothMargins.DropDown).ShowImageMargin = true; ((ContextMenuStrip)bothMargins.DropDown).ShowCheckMargin = true; // This ToolStripMenuItem has only an image margin. imageMarginOnly.DropDown = CreateCheckImageContextMenuStrip(); ((ContextMenuStrip)imageMarginOnly.DropDown).ShowImageMargin = true; ((ContextMenuStrip)imageMarginOnly.DropDown).ShowCheckMargin = false; // This ToolStripMenuItem has only a check margin. checkMarginOnly.DropDown = CreateCheckImageContextMenuStrip(); ((ContextMenuStrip)checkMarginOnly.DropDown).ShowImageMargin = false; ((ContextMenuStrip)checkMarginOnly.DropDown).ShowCheckMargin = true; // This ToolStripMenuItem has no image and no check margin. noMargins.DropDown = CreateCheckImageContextMenuStrip(); ((ContextMenuStrip)noMargins.DropDown).ShowImageMargin = false; ((ContextMenuStrip)noMargins.DropDown).ShowCheckMargin = false; // Populate the MenuStrip control with the ToolStripMenuItems. ms.Items.Add(bothMargins); ms.Items.Add(imageMarginOnly); ms.Items.Add(checkMarginOnly); ms.Items.Add(noMargins); // Dock the MenuStrip control to the top of the form. ms.Dock = DockStyle.Top; // Add the MenuStrip control to the controls collection last. // This is important for correct placement in the z-order. this.Controls.Add(ms); }
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.ScrollableControl
System.Windows.Forms.ToolStrip
System.Windows.Forms.ToolStripDropDown
System.Windows.Forms.ToolStripDropDownMenu
System.Windows.Forms.ContextMenuStrip
プラットフォーム
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- ToolStripDropDownMenu クラスのページへのリンク