树节点选定的文本文件将加载到文本框中 [英] Tree Node selected text file loades into text box

查看:77
本文介绍了树节点选定的文本文件将加载到文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看更多:C#
所以我想做一个树节点,当一个孩子被选中它加载一个文本文件(我有)到文本框中节点的权利.

这是我到目前为止所拥有图片的链接.

http://i978.photobucket.com/albums/ae266/athenso/HA/nodeprevies.png [^ ]

我想要它,就像沙漠探索被点击一样.用于沙漠探险的文本文件已加载到右侧的Richtext框中.它已锁定,因此无法进行编辑.但是,是的,如果有人可以提供帮助,我将不胜感激

See more: C#
So i want to do a TreeNode that when a child is selected it loads a text file (that i have) into a text box to the right of the node.

Here is a link to a picture of what i have so far.

http://i978.photobucket.com/albums/ae266/athenso/HA/nodeprevies.png[^]

i want it so like Desert Quest gets clicked. The text file for desert quest is loaded into the richtext box on the right. Its locked so it cant be edited. But yeah if anyone could help with that, i would appreciate it alot

推荐答案

处理TreeView.NodeMouseClick事件并使用e.Node属性选择节点. br/> 然后,您可以使用File.ReadAllLines读取文件并设置TextBox.Lines属性.
Handle the TreeView.NodeMouseClick event and use the e.Node property to select the node.
You can then read the file using File.ReadAllLines and set the TextBox.Lines property.


要对节点单击做出反应,可以使用 RichTextBox.LoadFile方法(字符串) [ ^ ]填充富文本框.

加法:

要标识该节点,您可以使用例如文本 [^ ]或标记 [ TreeNodeMouseClickEventArgs类 [
To react on an node click, you can use the TreeView.NodeMouseClick Event[^].

So in that event you can check which node was clicked and then if the node is the correct one you can use the RichTextBox.LoadFile Method (String)[^] to fill the rich text box.

Addition:

To identify the node, you can use for example the Text[^] or Tag[^] properties.

The event arguments of the NodeMouseClick include the node that was selected. See: TreeNodeMouseClickEventArgs Class[^]

Addition 2:
Instead of presuming that the file isn''t found check what the exception says. So change the code to:
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
       {
           try
           {
               // Look for a  spacific text in the node
               if (e.Node.Text.Contains("Desert Quest"))
               {
                   string DesertFile = "Z:\\Tibia Tool\\Quests\\DesertQuest.txt";
                   rchQuests.LoadFile(DesertFile, RichTextBoxStreamType.PlainText);
               }
           }
           } catch (System.IO.FileNotFoundException) {
              MessageBox.Show("File not found");
           }
           catch (System.Exception exception)
           {
              MessageBox.Show(exception.Message);
           }
       }


如果异常是未找到文件以外的其他东西,那也将为您提供确切的详细信息.


That would give you the exact details also if the exception is something else than file not found.


即使您编写"click",也很可能意味着处理节点选择事件,TreeView.AfterSelect:
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.beforeselect.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.afterselect.aspx [ ^ ].

此外,从您的问题还不清楚您是否使用WPF,Forms或其他东西.请始终对其进行标记.这个想法几乎是一样的.

—SA
Even though you write "click", most likely you mean handling the node selection events, TreeView.BeforeSelect, TreeView.AfterSelect:
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.beforeselect.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.afterselect.aspx[^].

Besides, from your question it''s not clear if you use WPF, Forms or something else. Please tag it, always. The idea is pretty much the same.

—SA


这篇关于树节点选定的文本文件将加载到文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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