When using Treeview, the right-click menu of A treenode is specified, but the Node Selected by right-click is not the node pointed to by the mouse, right-click the function in the menu, and the node to be operated cannot be selectednode. No answer is found for this problem, and a method is found in msdn to use getnodeat (point P) if you know P, you can find the node. The final implementation method is as follows: Find the node through the following code and set this node as selectednode in mousedown, in this way, the selectednode operation may be performed in the right-click menu. note: control is the form where Treeview is located.
/** // <Summary>
/// Obtain the node pointed to by the mouse in the Treeview, and set the node as the currently selected node
/// </Summary>
/// <Param name = "TV"> </param>
/// <Returns> </returns>
Public static treenode getmousenode (Treeview TV, Control)
{
Point Pt = control. pointtoscreen (TV. Location );
Point P = new point (control. mouseposition. X-Pt. X, Control. mouseposition. Y-Pt. y );
Treenode Tn = TV. getnodeat (P );
Return tn;
}