Treenode在点击它时会窃取焦点并将焦点设置在richtextbox上 [英] Treenode steal focus when clicking it and set focus on richtextbox

查看:107
本文介绍了Treenode在点击它时会窃取焦点并将焦点设置在richtextbox上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



当我使用WinForms在.NET 4.6中制作软件时,我遇到了一些问题。

我'我点击了一个treenode并将其保留在它上面后试图将注意力设置在richtextbox上。

当我运行我的软件并点击一个treenode时,焦点确实转到了richtextbox,但随后又返回到树视图。

在将焦点设置为richtextbox后,我没有对treeview进行编码以获得焦点。我发现如果我设置了消息框后我给了richtextbox焦点来检查treeview是否有焦点。焦点停留在richtextbox上,但如果没有消息框,我总是返回到树视图。



在splitContainer中的treeview和richtextbox。



基本上,我的软件是一个记笔记软件,我在树视图中显示文件夹和注释。用户将单击treenode以在richtextbox中打开所选注释。我想要使​​richtextbox聚焦,但如果我通过点击选择treenode ,焦点总是在聚焦richtextbox后返回到树视图。但是,如果我在键盘上使用向上或向下键,焦点将保留在richtextbox上。



如何将焦点集中在richtextbox上点击一个treenode打开一张纸条?



我尝试了什么:



我按照代码查看我是否在某处使树视图集中但不是。

Hi all,

I have a little problem while i am making my software in .NET 4.6 using WinForms.
I'm trying to set focus on richtextbox after i click a treenode and keep it on it.
When i run my software and click a treenode the focus did go to the richtextbox but then it return to the treeview.
I didn't code treeview to get the focus after set the focus to richtextbox. i found that if i set message box after i gave richtextbox focus to check if treeview is focused or not. The focus stay on richtextbox but if there isn't message box i always return to treeview.

The treeview and richtextbox both in a splitContainer.

Basically, my software is a note taking software and i show the folders and notes in a treeview. The user will click a treenode to open the selected note in a richtextbox. I want to make richtextbox focused but the focus always return to treeview after it focus the richtextbox if i select the treenode by click. But if i used up or down keys on keyboard the focus stays on the richtextbox.

How to keep the focus on the richtextbox when i click on a treenode to open a note?

What I have tried:

I follow the code to see if i somewhere make treeview focused but it isn't.

推荐答案

我不喜欢TreeView控件有很多原因,但这是一个新的......:叹息:



你可以做到,但这是一个主要的好处:

I dislike the TreeView control for many reasons, but this is a new one... :sigh:

You can do it, but it's a major kludge:
private void myTreeView_Enter(object sender, EventArgs e)
    {
    myRichTextBox.Focus();
    }

评论一下......或者你以后会删除它!

Comment it well ... or you'll remove it later!


这篇关于Treenode在点击它时会窃取焦点并将焦点设置在richtextbox上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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