right click in windows form

T

Tim Wallace

I have a simple app that I'm building using C# (using Visual C# Express
Edition). In it, I open an mdi child window that contains a treeview. I
want to display a context menu when the user right clicks the treeview.
When the window opens, I have to click on the treeview twice to get the menu
to show. I've tried setting the focus to the treeview in the Load even, to
no avail.

Any ideas?

Tim
 
G

Guest

Hi
you have to use the treeview mouse down event like that:
private void treeView1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if(e.Button==MouseButtons.Right)
{
Point p=new Point(e.X,e.Y);
contexmenu1.Show(treeView1,p);
}
}
 

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