WPF中的文本编辑器,带有包含快捷方式的工具栏 [英] Text editor in WPF with tool bar containing shortcuts

查看:140
本文介绍了WPF中的文本编辑器,带有包含快捷方式的工具栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个具有文本编辑器功能的简单应用程序.该编辑器允许创建新文档,打开现有文档/文件并进行编辑.
我正在使用工具栏和富文本框.
工具栏具有以下按钮/选项:
1.创建新文档
2.打开现有文档.
3.保存
4.另存为
5.切
6.复制
7.粘贴
8.撤消
9.重做
10.对齐(左,右和中心)
11.字体大小
12.字体样式(显示所有可用字体的下拉列表)
13.粗体
14.斜体
15.下划线

我已经完成了许多任务.但是我无法在富文本框中打开文档,也无法将另存为"功能以及字体大小和字体类型一起打开.

如果可以的话请帮助我.
在此先感谢您.

I am creating a simple application which has the feature of text editor. The editor allows to create new documents, open existing documents/files and also edit them.
I am using a toolbar and a rich text box.
The toolbar has the following buttons/Options:
1. Create new document
2. Open existing document.
3. Save
4. Save As
5. Cut
6. Copy
7. Paste
8. Undo
9. Redo
10. Alignment (left, right and center)
11. Font size
12. Font Style(which shows the drop down list of all the fonts available)
13. Bold
14. Italic
15. Underline

I have completed much of these tasks. But I am unable to open a document in rich text box and save & save As functionality along with the font size and font type.

Please help me if possible.
Thanks in advance.

推荐答案

要加载文件内容,可以使用下面指定的代码

for loading the file content you can use the code specified below

FileStream fStream = new FileStream("c:\\myfile.txt", FileMode.Open);
richTextBox1.Selection.Load(fStream, DataFormats.Text);



要保存内容,可以使用下面指定的代码



for saving the content you can use the code specified below

TextRange range;
FileStream fStream;
range = new TextRange(richTB.Document.ContentStart, richTB.Document.ContentEnd);
fStream = new FileStream("c:\\myfilenew.txt", FileMode.Create);
range.Save(fStream, DataFormats.Text);
fStream.Close(); 


这篇关于WPF中的文本编辑器,带有包含快捷方式的工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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