c# - NodeMouseClick 的问题 [英] c# - Problem with NodeMouseClick

查看:25
本文介绍了c# - NodeMouseClick 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 C# 中有一个 TreeView,我正在打开 NodeMouseClick 事件并根据单击的节点打开适当的表单,这工作正常.我的问题是一些节点有子节点,如果您单击该节点旁边的小 + 框,它将展开树,但它也会选择该父节点.我只是想让它扩展树而不是选择父级.知道我做错了什么或我能做什么吗?

I have a TreeView in C# that I am switching on the NodeMouseClick event and opening the appropriate form based on the node clicked which works fine. My question is some of the nodes have children and if you click the little + box next to that node it will expand the tree but it will also select that parent node. I just want it to expand the tree but not select the parent. Have any idea what I'm doing wrong or what I could do?

推荐答案

您可以在 NodeMouseClick 处理程序中使用以下代码来确定单击是发生在项目本身还是 + 框上.如果结果为 false,则您可以从处理程序返回,而无需执行现有操作.

You can use the following code to in your NodeMouseClick handler to determine if the click occured on the item itself or on the + box. If the result is false, then you can return from the handler without performing your existing action.

bool clickedItem = e.Node.Bounds.Contains(e.Location);

在我的测试中,通过使用 + 框展开节点不会更改所选节点.

In my test, the selected node is not changed by expanding a node using the + box.

这篇关于c# - NodeMouseClick 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆