Right click on treenode

S

Sean

Hi,

I have a treeview and user can right click the treenodes,
depending on the nodes, different shortcut menu will
appear.

I want only the shortcut menu to appear if the point of
the right mouse click is within the label text of the
treenode instead of row-wide.

I solved this problem already but when I right click the
treenode, there is a quick highlight on the treenode
regardless of wether the point of click is within the text
label or not. Does anyone know how to get rid of the quick
highlight? It's quite annoying [It hightlights for a
second and gone] when the point of right mouse click is
outside of the text label.

Thank you.

regards,
Sean
 
W

William Stacey [MVP]

I do not see this behavior with this method:

private void treeView1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if ( e.Button != MouseButtons.Right )
return;

System.Windows.Forms.TreeNode node = this.treeView1.GetNodeAt( e.X, e.Y );
if ( node == null )
this.cxMenuTreeHelp.Show(this.treeView1, new Point(e.X, e.Y));
else if ( node.Bounds.Contains(e.X, e.Y) )
this.cxMenuZone.Show(this.treeView1, new Point(e.X, e.Y));
else
this.cxMenuTreeHelp.Show(this.treeView1, new Point(e.X, e.Y));
}

Do you still see it using this?
 
G

Guest

Hi William,

Thank you for your reply.
I just tried your code but the problem still persists.

Actually, what I need is exactly like your code but on the
else part, I don't want the node to get selected:

if ( node == null )
this.cxMenuTreeHelp.Show(this.treeView1, new Point
(e.X, e.Y));
else if ( node.Bounds.Contains(e.X, e.Y) )
this.cxMenuZone.Show(this.treeView1, new Point(e.X,
e.Y));
else
//on this part: I don't want the node to get selected
this.cxMenuTreeHelp.Show(this.treeView1, new Point
(e.X, e.Y));

On the last else above, I don't want the node to get
selected.

Actually in the method treeview1_mousedown, I check to see
if the mouse click point is within bounds.
If it is, make that node to be the selectednode, else make
selectednode = null (meaning no blue highlight).

This works perfectly on left mouse click. However, the
right mouse click causes a quick blue highlight on the
treenode even though the point is out of the bounds.

I am now trying to eliminate the quick highlight on right
mouse click.
Please let me know if you have any other suggestion.


regards,
Sean
-----Original Message-----
I do not see this behavior with this method:

private void treeView1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if ( e.Button != MouseButtons.Right )
return;

System.Windows.Forms.TreeNode node =
this.treeView1.GetNodeAt( e.X, e.Y );
if ( node == null )
this.cxMenuTreeHelp.Show(this.treeView1, new Point(e.X, e.Y));
else if ( node.Bounds.Contains(e.X, e.Y) )
this.cxMenuZone.Show(this.treeView1, new Point(e.X, e.Y));
else
this.cxMenuTreeHelp.Show(this.treeView1, new Point(e.X, e.Y));
}

Do you still see it using this?
--
William Stacey, MVP

Hi,

I have a treeview and user can right click the treenodes,
depending on the nodes, different shortcut menu will
appear.

I want only the shortcut menu to appear if the point of
the right mouse click is within the label text of the
treenode instead of row-wide.

I solved this problem already but when I right click the
treenode, there is a quick highlight on the treenode
regardless of wether the point of click is within the text
label or not. Does anyone know how to get rid of the quick
highlight? It's quite annoying [It hightlights for a
second and gone] when the point of right mouse click is
outside of the text label.

Thank you.

regards,
Sean

.
 

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