从RichTextBox保存字符串 [英] Save string from RichTextBox

查看:68
本文介绍了从RichTextBox保存字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有一个记事本,就像真正的记事本一样.如果我保存一个文本(使用另存为"),然后对其进行修改,然后按保存",则会出现错误:该进程无法访问该文件,因为该文件已被另一个进程使用".保存按钮中的代码是这样的:

Hello, I have a Notepad made by me and it is like the real Notepad. If I save a text(with Save As) then I modify it and I press Save, an error appears: "The process cannot access the file because it is used by another process". The code from the Save button is this:

StreamWriter sw = new StreamWriter(loc);
     sw.Write(richTextBox1.Text);
     sw.Close();


loc是文本位置.
怎么了?您能告诉我正确的代码吗?


Where loc is the text location.
What is wrong? Can you tell me the correct code?

推荐答案

您可以在文件显示在文本框中的同时连接到文件.看看您是否要关闭它.
You would have connected to your file while you get its text to show in the textbox. See if you are closing that or not.


这篇关于从RichTextBox保存字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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