Copy TreeView Node

后端 未结 3 2080
离开以前
离开以前 2021-01-19 15:21

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 = (         


        
3条回答
  •  孤城傲影
    2021-01-19 16:05

    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;
            }
        }
    

提交回复
热议问题