本文整理匯總了VB.NET中System.Windows.Forms.Menu.GetContextMenu方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Menu.GetContextMenu方法的具體用法?VB.NET Menu.GetContextMenu怎麽用?VB.NET Menu.GetContextMenu使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Windows.Forms.Menu
的用法示例。
在下文中一共展示了Menu.GetContextMenu方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: AddContextmenu
Public Sub AddContextmenu()
' Create a shortcut menu.
Dim m As New ContextMenu()
Me.ContextMenu = m
' Create MenuItem objects.
Dim menuItem1 As New MenuItem()
Dim menuItem2 As New MenuItem()
' Set the Text property.
menuItem1.Text = "New"
menuItem2.Text = "Open"
' Add menu items to the MenuItems collection.
m.MenuItems.Add(menuItem1)
m.MenuItems.Add(menuItem2)
' Display the starting message.
MessageBox.Show("Right-click the form to display the shortcut menu items")
' Add functionality to the menu items.
AddHandler menuItem1.Click, AddressOf Me.menuItem1_Click
AddHandler menuItem2.Click, AddressOf Me.menuItem2_Click
End Sub
Private Sub menuItem1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim textReport As String = "You clicked the New menu item. " + vbCr + "It is contained in the following shortcut menu: " + vbCr + vbCr
' Get information on the shortcut menu in which menuitem1 is contained.
textReport += ContextMenu.GetContextMenu().ToString()
' Display the shortcut menu information in a message box.
MessageBox.Show(textReport, "The ContextMenu Information")
End Sub
Private Sub menuItem2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim textReport As String = "You clicked the Open menu item. " + vbCr + "It is contained in the following shortcut menu: " + vbCr + vbCr
' Get information on the shortcut menu in which menuitem1 is contained.
textReport += ContextMenu.GetContextMenu().ToString()
' Display the shortcut menu information in a message box.
MessageBox.Show(textReport, "The ContextMenu Information")
End Sub