Windows应用程序按钮和菜单项
问题描述:
如何创建一个在单击(普通左键)后将显示菜单项(上下文菜单)的按钮... ??
我创建了一个上下文菜单,并试图在单击按钮时显示该菜单.
它正在显示,但无法设置上下文菜单的正确位置.
这是代码:
How to create a button which will show menu items(Context Menu) after clicking(Normal Left Click) it....?
I have created a context menu and trying to show that on button click.
It is showing but can not set the proper location of context menu.
Here is Code :
private void button1_Click(object sender, EventArgs e)
{
contextMenuStrip1.Visible = true;
contextMenuStrip1.Left = button1.Left;
contextMenuStrip1.Top = button1.Top - contextMenuStrip1.Height;
}
我希望右键单击按钮后,上下文菜单应该显示在按钮上方.
请帮助!!!
I want context menu should be display above the button after clicking button.
Please HELP !!!
答
我认为您正在寻找以下内容:
SplitButton:XP样式下拉拆分按钮 [
I think you are looking for this:
SplitButton: an XP style dropdown split button[^]
------
Ok so try this:
contextMenuStrip1.Show(MousePosition);
------
然后执行:
------
Then do:
Point pt = PointToScreen(button1.Location);
//or this one
//Point pt = PointToScreen(new Point(button1.Right, button1.Top));
contextMenuStrip1.Show(pt);