</pre><p>1. 将内容转换为数组</p><pre name="code" class="csharp">FlowDocument fd = richTextBox1.Document;
System.IO.Stream s = new System.IO.MemoryStream();
System.Windows.Markup.XamlWriter.Save(fd, s);
byte[] data = new byte[s.Length];
s.Position = 0;
s.Read(data, 0, data.Length);s.Close();
2. 从数组中加载内容
System.IO.Stream news = new System.IO.MemoryStream(data);
FlowDocument newfd = System.Windows.Markup.XamlReader.Load(news) as FlowDocument;
richTextBox2.Document = newfd;
3. 命令
复制: ToolBarCopy.Command = System.Windows.Input.ApplicationCommands.Copy;
剪切: toolBarCut.Command = System.Windows.Input.ApplicationCommands.Cut;
粘贴: ToolBarPaste.Command = System.Windows.Input.ApplicationCommands.Paste;
撤销: ToolBarUndo.Command = System.Windows.Input.ApplicationCommands.Undo;
复原: ToolBarRedo.Command = System.Windows.Input.ApplicationCommands.Redo;
文字居中: toolBarContentCenter.Command = System.Windows.Documents.EditingCommands.AlignCenter;
文字居右: toolBarContentRight.Command = System.Windows.Documents.EditingCommands.AlignRight;
文字居左: toolBarContentLeft.Command = System.Windows.Documents.EditingCommands.AlignLeft;
有序排列: ToolBarNumbering.Command = System.Windows.Documents.EditingCommands.ToggleNumbering;
无序排列: ToolBarBullets.Command = System.Windows.Documents.EditingCommands.ToggleBullets;
在实际使用时发现只这样操作的话,按钮无法点击,需将按钮放在toolbar里才可。
4. 设置颜色
System.Windows.Media.Color clr =
System.Windows.Media.Color.FromArgb(BkColor.A,BkColor.R,BkColor.G,BkColor.B);
richTextBox1.Selection.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(clr));
5. 设置字体
richTextBox1.Selection.ApplyPropertyValue(TextElement.FontFamilyProperty,SelFnt);
6. 设置大小
richTextBox1.Selection.ApplyPropertyValue(TextElement.FontSizeProperty, isize.ToString());
isize是整型