复制 TreeView 节点

Copy TreeView Node(复制 TreeView 节点)

本文介绍了复制 TreeView 节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将选定的树视图节点复制到剪贴板,以便将其粘贴到记事本中.这是我的代码,但它不起作用.

I am trying to copy the selected treeview node to the clip board so I can paste it in notepad. Here is my code but it doesn't work.

    TreeNode selNode = (TreeNode)this.treeView1.SelectedNode;
    Clipboard.SetData("TreeNode", selNode);

推荐答案

记事本对 Winforms TreeNode 类一无所知.请改用 Clipboard.SetText():

Notepad doesn't know anything about the Winforms TreeNode class. Use Clipboard.SetText() instead:

    private void treeView1_KeyDown(object sender, KeyEventArgs e) {
        if (e.KeyData == (Keys.Control | Keys.C)) {
            if (treeView1.SelectedNode != null) {
                Clipboard.SetText(treeView1.SelectedNode.Text);
            }
            e.SuppressKeyPress = true;
        }
    }

这篇关于复制 TreeView 节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:复制 TreeView 节点

基础教程推荐