C#代码 收藏代码
private void treeList1_MouseUp(object sender, MouseEventArgs e)
{
TreeList tree = sender as TreeList;
if (e.Button == MouseButtons.Right
&& ModifierKeys == Keys.None
&& treeList1.State == TreeListState.Regular)
{
Point p = new Point(Cursor.Position.X, Cursor.Position.Y);
TreeListHitInfo hitInfo = tree.CalcHitInfo(e.Location);
if (hitInfo.HitInfoType == HitInfoType.Cell)
{
tree.SetFocusedNode(hitInfo.Node);
}
if (tree.FocusedNode != null)
{
popupMenu1.ShowPopup(p);
}
}
}
添加到鼠标事件中,此处以TreeList为例: