ContextMenu.Show 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在指定位置显示快捷菜单。
重载
Show(Control, Point) |
在指定位置显示快捷菜单。 |
Show(Control, Point, LeftRightAlignment) |
在指定的位置使用指定的对齐方式显示快捷菜单。 |
Show(Control, Point)
在指定位置显示快捷菜单。
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 当用户单击 绑定到的窗体的控件或区域的鼠标右键时, ContextMenu 将显示 。 可以使用此方法在特定位置手动显示快捷菜单,并将其与特定控件绑定。 在关闭菜单之前,此方法不会返回。
适用于
Show(Control, Point, LeftRightAlignment)
在指定的位置使用指定的对齐方式显示快捷菜单。
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
参数的控件的对齐方式。