当前位置:网站首页>RichTextbox 操作
RichTextbox 操作
2022-07-20 16:13:00 【ima_zhan】
</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是整型 边栏推荐
猜你喜欢
李宏毅老师2020年深度学习系列讲座笔记2
网络安全学习(五)DHCP
李宏毅老师2020年深度学习系列讲座笔记7
氢创未来,中国氢能联盟举办2022氢能专精特新创业大赛启动仪式
商城异地多活架构设计
Mdclub lightweight web forum source code
Some things about pointer array and array pointer
廖雪峰老師系列課程 迅速過一遍 1
VMware low version starts the blue screen solution of virtual machine (it takes 3 days to restart the installation experience, which must be seen before installation)
Programmers are new to the workplace, how to plan their career?
随机推荐
Tmech publishes the latest progress in the operation control technology of the must choose: to realize the high robustness walking of humanoid robots
短信验证
[2022 Huawei developer competition series live broadcast] who can't wait for the wonderful combination of database veterans + best-selling authors?
19_内置指令
廖雪峰老師系列課程 迅速過一遍 1
Network Security Learning (VII) IIS
遮天三部曲
wmware启用虚拟化功能报错
Kubevirt manages virtual machines
20_ Custom instructions
Hydrogen future, China hydrogen energy alliance held the launching ceremony of 2022 hydrogen energy specialty and new entrepreneurship competition
对于IT互联网行业来说,家觉得学历重要还是能力?
20_自定义指令
IBM MQ operation and maintenance manual
网络安全学习(三)基本DOS命令
Acwing game 60 [End]
一文了解工业互联网标识解析二级节点
VMware低版本启动虚拟机蓝屏解决方案(重启了3天才安装好的经验,装前必看)
(‘You must install pydot (`pip install pydot`) and install graphviz...)
%s、%1$s、%d、%1$d占位符