从Visual Studio文本框中复制并粘贴到记事本或MS WOrd中 [英] Copy from Visual Studio Text Box and Paste in Notepad or MS WOrd

查看:137
本文介绍了从Visual Studio文本框中复制并粘贴到记事本或MS WOrd中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

H大家...

在我的C#.net桌面应用程序中,我想从文本文件中复制文本,并希望将该文本粘贴到记事本或MS Word或Word Pad中.

我用
string.Copy(String str);
复制该文本文件的文本,但是当打开MS Word或Note Pad或Word Pad时,不会粘贴任何内容.

如何从VS Test Box中将一个文本粘贴到MS Word或Note Pad或Word Pad中?

H Everyone...

In my C# .net desktop application i want to copy text from a text file and want to paste that text into a notepad or MS Word or Word pad .

i use
string.Copy(String str);
to copy the text of that Text file but when open a MS Word or Note Pad or Word Pad ,nothing to be pasted .

how to paste one text into MS Word or Note Pad or Word Pad from VS Test Box ?

推荐答案

使用以下代码

Use below code

Clipboard.SetText(txtClipboard.Text);



另请参考使用C#剪贴板复制和粘贴 [



Also refer Clipboard Copy and Paste with C#[^]


您只需要将字符串写入文本文件,然后将其存储在所需的路径中即可.假设您的数据在字符串strValue中:
You just need to write the string into text file and store it at desired path. Suppose your data is in string strValue:
string strValue = "your data";

FileStream fs = new FileStream("D:\\test.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, SeekOrigin.End);
sw.WriteLine(strValue);
sw.Flush();
sw.Close();


如果不存在,则会在D驱动器中创建一个文件test.txt.否则它将追加.如果您不想每次都添加和创建新文件,则可以在写入之前删除.


this will create a file test.txt in your D drive if it doesn''t exist. otherwise it will append. if u don''t want to append and create new file everytime, you can just delete before writing.

if (File.Exists("D:\\test.txt");
	File.Delete("D:\\test.txt");



包含System.IO名称空间.



Inclue System.IO namespace.


这篇关于从Visual Studio文本框中复制并粘贴到记事本或MS WOrd中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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