ContextMenuStrip簡單使用

 

(1)來源

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

 

(2)繼承層次

System.Object
  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

 

(3)重要成員

.Items :獲取屬於 ToolStrip 的所有項。

Show(Point) :相對於指定的屏幕位置定位 ToolStripDropDown

 

(4)例子

//在Form_Load響應函數中

contextMenuStrip1.Items.Add("apple");

contextMenuStrip1.Items.Add("banana");

contextMenuStrip1.Items.Add("pear");

//在鼠標按下響應函數中

if (e.Button == MouseButtons.Right)

{

     contextMenuStrip1.Show(Cursor.Position);

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章