问题描述
亲爱的所有人,
我正在Windows应用程序上工作,我需要将所有文本从文本框中复制到记事本文件中.我可以将所有文本从文本框复制到剪贴板,但是现在如何将剪贴板文本复制到记事本文件.
任何形式的链接,建议和特别的专家建议都将受到高度赞赏.
谢谢与问候,
Balkrishna Raut
Dear All,
i am working on windows application and i need to copy all the text from text box to notepad file. i can copy all the text from text box to clipboard but now how can i copy this clipboard text to Notepad file.
Any kind of link, suggestion and specially expert advice would be highly appreciated.
Thanks & Regards,
Balkrishna Raut
推荐答案
File.AppendAllText(@"C:\MyNotepadFile.txt",Clipboard.GetText());
关于此方法的最好之处在于,即使文件不存在,它也会创建一个.
如果要覆盖内容,可以使用此方法:
The best thing about this method is that, even if the file doesn''t exist, it will create one.
If want to overwrite the content, you can use this :
File.WriteAllText(@"C:\MyNotepadFile.txt",ClipBoard.GetText());
File.WriteAllText(@"C:\MyNotepadFile.txt", myTextBox.Text);
(感谢其他张贴者提醒我该方法)
然后,如果要在记事本中打开文件,则可以使用Process.Start对文件进行外壳处理.但是我不知道为什么要这么做,因为用户已经可以在文本框中看到内容了.
(thanks to other posters for reminding me of that method)
You can then shell the file using Process.Start if you want to have it open in Notepad. But I have no idea why you would want to do that, since the user can see the content in your textbox already.
这篇关于如何使用C#将剪贴板数据粘贴到记事本上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!