WPF 中RichTextBox控制元件用法細講
讀取RichTextBox的內容到string,將字串儲存到資料庫的方法就不寫了,大家都會
string GetTextByRichBox(RichTextBox box)
{
MemoryStream s = new MemoryStream();
TextRange documentTextRange = new TextRange(box.Document.ContentStart, box.Document.ContentEnd);
documentTextRange.Save(s, DataFormats.XamlPackage);
return Convert.ToBase64String(s.ToArray());
}
將string的內容轉換成圖片顯示在RichTextBox中
private ShowTextToRichBox(RichTextBox box)
{
MemoryStream s = new MemoryStream((Convert.FromBase64String(Convert.ToString(dr["D_DESC"]))));
TextRange TR = new TextRange(box.Document.ContentStart,box.Document.ContentEnd);
TR.Load(s, DataFormats.XamlPackage);
}