ContextMenu.Show 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
显示位于指定位置的快捷菜单。
重载
| 名称 | 说明 |
|---|---|
| Show(Control, Point) |
显示位于指定位置的快捷菜单。 |
| Show(Control, Point, LeftRightAlignment) |
显示位于指定位置且具有指定对齐方式的快捷菜单。 |
Show(Control, Point)
- Source:
- ContextMenu.cs
- Source:
- ContextMenu.cs
显示位于指定位置的快捷菜单。
public:
void Show(System::Windows::Forms::Control ^ control, System::Drawing::Point pos);
public void Show(System.Windows.Forms.Control control, System.Drawing.Point pos);
member this.Show : System.Windows.Forms.Control * System.Drawing.Point -> unit
Public Sub Show (control As Control, pos As Point)
参数
例外
参数 control 为 null.
控件的句柄不存在或控件不可见。
示例
下面的代码示例演示如何构造快捷菜单并使用 Show 该方法。 若要运行该示例,请将以下代码粘贴到包含名为 Button1 的按钮的窗体中。 确保所有事件都与其事件处理方法相关联。
// Displays the shortcut menu, offsetting its location
// from the upper-left corner of Button1 by 20 pixels in each direction.
void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
//Declare the menu items and the shortcut menu.
array<MenuItem^>^menuItems = {gcnew MenuItem( "Some Button Info" ),gcnew MenuItem( "Some Other Button Info" ),gcnew MenuItem( "Exit" )};
System::Windows::Forms::ContextMenu^ buttonMenu = gcnew System::Windows::Forms::ContextMenu( menuItems );
buttonMenu->Show( Button1, System::Drawing::Point( 20, 20 ) );
}
// Displays the shortcut menu, offsetting its location
// from the upper-left corner of Button1 by 20 pixels in each direction.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Declare the menu items and the shortcut menu.
MenuItem[] menuItems = new MenuItem[]{new MenuItem("Some Button Info"),
new MenuItem("Some Other Button Info"), new MenuItem("Exit")};
ContextMenu buttonMenu = new ContextMenu(menuItems);
buttonMenu.Show(Button1, new System.Drawing.Point(20, 20));
}
' Displays the shortcut menu, offsetting its location
' from the upper-left corner of Button1 by 20 pixels in each direction.
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
'Declare the menu items and the shortcut menu.
Dim menuItems() As MenuItem = New MenuItem() _
{New MenuItem("Some Button Info"), _
New MenuItem("Some Other Button Info"), _
New MenuItem("Exit")}
Dim buttonMenu As New ContextMenu(menuItems)
buttonMenu.Show(Button1, New System.Drawing.Point(20, 20))
End Sub
注解
通常,当用户单击绑定到的窗体ContextMenu的控件或区域的鼠标右键时,会显示 aContextMenu。 可以使用此方法在特定位置手动显示快捷菜单,并将其绑定到特定控件。 此方法在关闭菜单之前不会返回。
适用于
Show(Control, Point, LeftRightAlignment)
- Source:
- ContextMenu.cs
- Source:
- ContextMenu.cs
显示位于指定位置且具有指定对齐方式的快捷菜单。
public:
void Show(System::Windows::Forms::Control ^ control, System::Drawing::Point pos, System::Windows::Forms::LeftRightAlignment alignment);
public void Show(System.Windows.Forms.Control control, System.Drawing.Point pos, System.Windows.Forms.LeftRightAlignment alignment);
member this.Show : System.Windows.Forms.Control * System.Drawing.Point * System.Windows.Forms.LeftRightAlignment -> unit
Public Sub Show (control As Control, pos As Point, alignment As LeftRightAlignment)
参数
- alignment
- LeftRightAlignment
一个 LeftRightAlignment ,指定控件相对于参数的 pos 对齐方式。