在TreeView中添加MouseUp事件,再在事件响应中判断是否为右键
private void OnMouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
// We are only interested in right mouse clicks
if( e.Button == MouseButtons.Right )
{
// Attempt to get the node the mouse clicked on
TreeNode node = treeAlbum.GetNodeAt(e.X, e.Y);
if(node != null)
{
// Select the tree item
treeAlbum.SelectedNode = node;
// Add What's you want
}
}
}
private void OnMouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
// We are only interested in right mouse clicks
if( e.Button == MouseButtons.Right )
{
// Attempt to get the node the mouse clicked on
TreeNode node = treeAlbum.GetNodeAt(e.X, e.Y);
if(node != null)
{
// Select the tree item
treeAlbum.SelectedNode = node;
// Add What's you want
}
}
}
非常感谢你的回复
ContextMenu1.Show(treeAlbum, new Point(e.X, e.Y));
在这儿treeAlblum是一个TreeView实例,然后你就可以对ContextMenu操作了,我想Shawls大概就是这个意思吧