日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > asp.net >内容正文

asp.net

WPF 操作 richTextBox

發(fā)布時(shí)間:2023/12/1 asp.net 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WPF 操作 richTextBox 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

FROM:http://blog.csdn.net/wuzhengqing1/article/details/7010902

?

取出richTextBox里面的內(nèi)容

第一種方法:

將richTextBox的內(nèi)容以字符串的形式取出 ??

string xw = System.Windows.Markup.XamlWriter.Save(richTextBox.Document);

第二種方法:將richTextBox的類(lèi)容以二進(jìn)制數(shù)據(jù)的方法取出 ????

FlowDocument document = richTextBox.Document; ????

System.IO.Stream s = new System.IO.MemoryStream(); ????

System.Windows.Markup.XamlWriter.Save(document, s);???????? ??

byte[] data = new byte[s.Length]; ????

s.Position = 0; ????

s.Read(data, 0, data.Length); ?????

s.Close();

賦值給richTextBox

第一種方法:

將字符串轉(zhuǎn)換為數(shù)據(jù)流賦值給richTextBox中? ?

System.IO.StringReader sr = new System.IO.StringReader(xw); ?

System.Xml.XmlReader xr = System.Xml.XmlReader.Create(sr); ?

richTextBox1.Document = (FlowDocument)System.Windows.Markup.XamlReader.Load(xr);

第二種方法:

將二進(jìn)制數(shù)據(jù)賦值給richTextBox ??

System.IO.Stream ss = new System.IO.MemoryStream(data); ???

FlowDocument doc = System.Windows.Markup.XamlReader.Load(ss) as FlowDocument; ????

ss.Close(); ????

richTextBox1.Document = doc;

?

清空RichTextBox的方法

System.Windows.Documents.FlowDocument doc = richTextBox.Document; ????????

doc.Blocks.Clear();

?

如何將一個(gè)String類(lèi)型的字符串賦值給richTextBox

myRTB.Document = new FlowDocument(new Paragraph(new Run(myString)));

FlowDocument doc = new FlowDocument();

Paragraph p = new Paragraph();? // Paragraph 類(lèi)似于 html 的 P 標(biāo)簽

Run r = new Run(myString);????? // Run 是一個(gè) Inline 的標(biāo)簽 p.Inlines.Add(r); doc.Blocks.Add(p); myRTB.Document = doc;

如何將richTextBox中的內(nèi)容以rtf的格式完全取出 ???????????

string rtf = string.Empty; ???????????

TextRange textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd); ???????????

using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) ???????????

{ ???????????????

textRange.Save(ms, System.Windows.DataFormats.Rtf); ???????????????

ms.Seek(0, System.IO.SeekOrigin.Begin); ???????????????

System.IO.StreamReader sr = new System.IO.StreamReader(ms); ???????????????

rtf = sr.ReadToEnd(); ???????????

} ????

?

操作RichTextBox 復(fù)制?? ToolBarCopy.Command = System.Windows.Input.ApplicationCommands.Copy;

剪切?? toolBarCut.Command = System.Windows.Input.ApplicationCommands.Cut;

粘貼?? ToolBarPaste.Command = System.Windows.Input.ApplicationCommands.Paste;

撤銷(xiāo)?? ToolBarUndo.Command = System.Windows.Input.ApplicationCommands.Undo;

復(fù)原?? 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;

無(wú)序排列? ToolBarBullets.Command = System.Windows.Documents.EditingCommands.ToggleBullets;

字體變大 ???????????

int fontSize = Convert.ToInt32(richTextBox.Selection.GetPropertyValue(TextElement.FontSizeProperty)); ???????????

fontSize++; ???????????

richTextBox.Selection.ApplyPropertyValue(TextElement.FontSizeProperty, fontSize.ToString());

轉(zhuǎn)載于:https://www.cnblogs.com/alex-zhao/archive/2012/09/16/2688003.html

總結(jié)

以上是生活随笔為你收集整理的WPF 操作 richTextBox的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。