But, you know I add a ToolBar component in my form, there are many buttons in the ToolBar, I hope to open the context menu when I left-click a button, If I use you code, the context menu always is opened whichever button is left-clicked. Maybe what I need to know is how to get the cursor's position, in screen coordinates, but I don't know how to do. In Delphi ,maybe I can get it by using GetCursorPos , then change it to local coordinates, but In C#, I don't know how to do!
How can I open a context menu by left-click?
Wolfgang W.
Try this:
public class Form1 : Form
{
private System.Windows.Forms.ContextMenu contextMenu1;
private void InitializeComponent()
{
...
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
contextMenu1.Show(this, new Point(e.X, e.Y));
}
}
BDH
Nima Dilmaghani
But, you know I add a ToolBar component in my form, there are many buttons in the ToolBar, I hope to open the context menu when I left-click a button, If I use you code, the context menu always is opened whichever button is left-clicked.
Maybe what I need to know is how to get the cursor's position, in screen coordinates, but I don't know how to do. In Delphi ,maybe I can get it by using GetCursorPos , then change it to local coordinates, but In C#, I don't know how to do!
Ayman Shoukry