共用方式為


ToolStripDropDownMenu 建構函式

定義

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

public:
 ToolStripDropDownMenu();
public ToolStripDropDownMenu ();
Public Sub New ()

範例

下列程式碼範例示範如何建立和初始化 ContextMenuStrip 控制項。 如需完整的程式代碼清單,請參閱 如何:在 CoNtextMenuStrip 控制項中啟用檢查邊界和影像邊界

// This utility method creates a ContextMenuStrip control
// that has four ToolStripMenuItems showing the four 
// possible combinations of image and check margins.
internal ContextMenuStrip CreateCheckImageContextMenuStrip()
{
    // Create a new ContextMenuStrip control.
    ContextMenuStrip checkImageContextMenuStrip = new ContextMenuStrip();

    // Create a ToolStripMenuItem with a
    // check margin and an image margin.
    ToolStripMenuItem yesCheckYesImage = 
        new ToolStripMenuItem("Check, Image");
    yesCheckYesImage.Checked = true;
    yesCheckYesImage.Image = CreateSampleBitmap();

    // Create a ToolStripMenuItem with no
    // check margin and with an image margin.
    ToolStripMenuItem noCheckYesImage = 
        new ToolStripMenuItem("No Check, Image");
    noCheckYesImage.Checked = false;
    noCheckYesImage.Image = CreateSampleBitmap();

    // Create a ToolStripMenuItem with a
    // check margin and without an image margin.
    ToolStripMenuItem yesCheckNoImage = 
        new ToolStripMenuItem("Check, No Image");
    yesCheckNoImage.Checked = true;

    // Create a ToolStripMenuItem with no
    // check margin and no image margin.
    ToolStripMenuItem noCheckNoImage = 
        new ToolStripMenuItem("No Check, No Image");
    noCheckNoImage.Checked = false;

    // Add the ToolStripMenuItems to the ContextMenuStrip control.
    checkImageContextMenuStrip.Items.Add(yesCheckYesImage);
    checkImageContextMenuStrip.Items.Add(noCheckYesImage);
    checkImageContextMenuStrip.Items.Add(yesCheckNoImage);
    checkImageContextMenuStrip.Items.Add(noCheckNoImage);

    return checkImageContextMenuStrip;
}
' This utility method creates a ContextMenuStrip control
' that has four ToolStripMenuItems showing the four 
' possible combinations of image and check margins.
Friend Function CreateCheckImageContextMenuStrip() As ContextMenuStrip
   ' Create a new ContextMenuStrip control.
   Dim checkImageContextMenuStrip As New ContextMenuStrip()
   
   ' Create a ToolStripMenuItem with a
   ' check margin and an image margin.
   Dim yesCheckYesImage As New ToolStripMenuItem("Check, Image")
   yesCheckYesImage.Checked = True
   yesCheckYesImage.Image = CreateSampleBitmap()
   
   ' Create a ToolStripMenuItem with no
   ' check margin and with an image margin.
   Dim noCheckYesImage As New ToolStripMenuItem("No Check, Image")
   noCheckYesImage.Checked = False
   noCheckYesImage.Image = CreateSampleBitmap()
   
   ' Create a ToolStripMenuItem with a
   ' check margin and without an image margin.
   Dim yesCheckNoImage As New ToolStripMenuItem("Check, No Image")
   yesCheckNoImage.Checked = True
   
   ' Create a ToolStripMenuItem with no
   ' check margin and no image margin.
   Dim noCheckNoImage As New ToolStripMenuItem("No Check, No Image")
   noCheckNoImage.Checked = False
   
   ' Add the ToolStripMenuItems to the ContextMenuStrip control.
   checkImageContextMenuStrip.Items.Add(yesCheckYesImage)
   checkImageContextMenuStrip.Items.Add(noCheckYesImage)
   checkImageContextMenuStrip.Items.Add(yesCheckNoImage)
   checkImageContextMenuStrip.Items.Add(noCheckNoImage)
   
   Return checkImageContextMenuStrip
 End Function

適用於