当树视图没有焦点时,C# WinForms 突出显示树节点 [英] C# WinForms highlight treenode when treeview doesn't have focus

查看:36
本文介绍了当树视图没有焦点时,C# WinForms 突出显示树节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个界面来编辑游戏的场景.基本上它由具有嵌套条件和动作的事件组成.因此,我计划使用两个树视图 - 一个用于选择事件,另一个用于选择事件中的条件/操作进行编辑.

I'm making an interface to edit scenarios for a game. Basically it consists of events, which have nested conditions and actions. So, I planned on using two treeviews - one for selecting the event, and other for selecting the condition/action inside the event to edit.

现在,你看,如果我选择一个事件(在左树视图中),然后尝试在右树视图中选择一些东西,左树视图将停止显示蓝色选择矩形.这显然很糟糕,因为现在用户不知道他正在编辑哪个事件!

Now, you see, if I select an event (in left treeview) and then try to select something in the right treeview, the left treeview will stop showing the blue selection rectangle. This is obviously bad because now the user doesn't know which event is he editing!

我发现保留有关当前选择内容的某种信息的唯一方法是使用 SelectedImageIndex,但这只是一个不同的小图像.

The only way I found to retain some sort of information about what is the current selection is by using SelectedImageIndex, but that's only one little image that will be different.

在没有关注树视图的情况下,有没有其他方法可以突出显示树节点?我知道我可以只使用 Graphics.DrawRectangle 什么的,但我听说绘图应该在 Paint 事件中完成,而 treeview 没有绘制事件......所以我想如果我在失去焦点的事件上绘制它,然后拖动窗体外的屏幕什么的,它会被擦除"吗?

Is there any other way to highlight the treenode while there is no focus on the treeview? I know I can just use Graphics.DrawRectangle or something, but I heard that drawing should be done in Paint event and treeview has no paint event... So I guess if I draw it on the event of losing focus, and then drag the form out of the screen or something, it will be "erased"?

无论如何,请告诉我您是否有想法(除了为选定和未选定的树节点使用单独的图标之外).

Anyway, please tell me if you got an idea (other than using a separate icon for selected and not selected treenode).

推荐答案

您要查找的是 TreeView 上的 HideSelection 属性.

What you are looking for is the HideSelection property on the TreeView.

来自 MSDN:

获取或设置一个值,该值指示即使树视图失去焦点,所选树节点是否仍保持突出显示.

Gets or sets a value indicating whether the selected tree node remains highlighted even when the tree view has lost the focus.

链接:http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.hideselection.aspx

代码:

TreeView.HideSelection = false;

这篇关于当树视图没有焦点时,C# WinForms 突出显示树节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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