Shape.ContextMenu Property
Gets or sets the shortcut menu associated with a line or shape control.
Namespace: Microsoft.VisualBasic.PowerPacks
Assembly: Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)
Syntax
'宣告
<BrowsableAttribute(False)> _
Public Overridable Property ContextMenu As ContextMenu
Get
Set
[BrowsableAttribute(false)]
public virtual ContextMenu ContextMenu { get; set; }
[BrowsableAttribute(false)]
public:
virtual property ContextMenu^ ContextMenu {
ContextMenu^ get ();
void set (ContextMenu^ value);
}
[<BrowsableAttribute(false)>]
abstract ContextMenu : ContextMenu with get, set
[<BrowsableAttribute(false)>]
override ContextMenu : ContextMenu with get, set
function get ContextMenu () : ContextMenu
function set ContextMenu (value : ContextMenu)
Property Value
Type: System.Windows.Forms.ContextMenu
A ContextMenu that represents the shortcut menu for the control, or a null reference (Nothing in Visual Basic) if there is no ContextMenu assigned. The default is a null reference (Nothing in Visual Basic).
Remarks
Use shortcut menus to give context-specific menu options to users when they right-click the control.
If a ContextMenuStrip has also been assigned to the control, the ContextMenu property takes precedence over the ContextMenuStrip property.
Examples
The following example displays the ContextMenu assigned to an OvalShape control when the right mouse button is clicked and released. This code requires that you have a Form with an OvalShape control on it. It is also required that the OvalShape has a ContextMenu assigned to its ContextMenu property.
Private Sub OvalShape1_MouseUp(
ByVal sender As Object,
ByVal e As MouseEventArgs
) Handles OvalShape1.MouseUp
' If the right mouse button is clicked and released,
' display the shortcut menu assigned to the OvalShape.
If e.Button = MouseButtons.Right Then
OvalShape1.ContextMenu.Show(Me, New Point(e.X, e.Y))
End If
End Sub
private void ovalShape1_MouseUp(object sender, MouseEventArgs e)
{
// If the right mouse button is clicked and released,
// display the shortcut menu assigned to the OvalShape.
if (e.Button == MouseButtons.Right)
{
ovalShape1.ContextMenu.Show(this, new Point(e.X, e.Y));
}
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
See Also
Reference
Microsoft.VisualBasic.PowerPacks Namespace
Other Resources
How to: Draw Lines with the LineShape Control (Visual Studio)
How to: Draw Shapes with the OvalShape and RectangleShape Controls (Visual Studio)