发布网友 发布时间:2022-05-16 11:36
共2个回答
热心网友 时间:2022-05-16 13:05
<RichTextBox Name="richTB"> <FlowDocument> <Paragraph> <Run>Paragraph 1</Run> </Paragraph> <Paragraph> <Run>Paragraph 2</Run> </Paragraph> <Paragraph> <Run>Paragraph 3</Run> </Paragraph> </FlowDocument> </RichTextBox> 以下代码实现一个将 RichTextBox 作为参数的方法并返回表示一个 RichTextBox 的纯文本内容的字符串。 Private Function StringFromRichTextBox(ByVal rtb As RichTextBox) As String ' TextPointer to the start of content in the RichTextBox. ' TextPointer to the end of content in the RichTextBox. Dim textRange As New TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd) ' The Text property on a TextRange object returns a string ' representing the plain text content of the TextRange. Return textRange.Text End Function string StringFromRichTextBox(RichTextBox rtb) { TextRange textRange = new TextRange( // TextPointer to the start of content in the RichTextBox. rtb.Document.ContentStart, // TextPointer to the end of content in the RichTextBox. rtb.Document.ContentEnd ); // The Text property on a TextRange object returns a string // representing the plain text content of the TextRange. return textRange.Text; }