RichTextBox에서 RTF를 얻는 방법
-
03-07-2019 - |
문제
RTF의 텍스트를 어떻게 얻습니까? RichTextBox
? 나는 이렇게 얻으려고 노력하고 있지만 속성은 존재하지 않습니다.
RichTextBox rtb = new RichTextBox();
string s = rtb.Rtf;
해결책
RichTextBox 내부에서 사용자가 생성 한 실제 XAML을 얻으려면 :
TextRange tr = new TextRange(myRichTextBox.Document.ContentStart,
myRichTextBox.Document.ContentEnd);
MemoryStream ms = new MemoryStream();
tr.Save(ms, DataFormats.Xaml);
string xamlText = ASCIIEncoding.Default.GetString(ms.ToArray());
편집 : 테스트 할 코드가 없지만 인스턴스 TextRange
유형에는 a가 있습니다 Save
(스트림) DataFormats
매개 변수 DataFormats.Rtf
다른 팁
Winforms 프레임 워크와 WPF 프레임 워크의 2 개의 RichTextBox 클래스가 있습니다.
System.Windows.Controls.RichTextBox wpfBox;
System.Windows.Forms.RichTextBox winformsBox;
WinForms RichTextBox 만 RTF 속성을 가지고 있고 다른 하나는 FlowDocument가 포함 된 문서 속성이 있습니다.
제휴하지 않습니다 StackOverflow