Showing context menu on a right click

A

avanti

Hi,

I am trying to show a context menu on a right click in some of my
controls. I want to show it at the right location. However it is
getting shown away from the mouse click location. Here is the code:


private void QueryTreeView_Clicked(object sender, EventArgs
args)
{
MouseEventArgs margs = (MouseEventArgs)args;
if (margs.Button ==
System.Windows.Forms.MouseButtons.Right)
{
TreeNode currentNode =
QueryTreeView.GetNodeAt(margs.X, margs.Y);
if (currentNode != null)
{
MenuItem[] items = new MenuItem[4];
if(currentNode.ImageIndex == 0)
{
items[0] = new MenuItem("Group");
items[1] = new MenuItem("Edit Filter");
items[2] = new MenuItem("Delete");
items[3] = new MenuItem("xxx");
System.Windows.Forms.ContextMenu cmenu = new
ContextMenu(items);
cmenu.Show(this, new Point(margs.X, margs.Y))
}
}
}
}


Am I missing something?


Thanks,
Avanti
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top