如何:从 RichTextBox 中提取文本内容麻烦告诉我
1个回答
展开全部
<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; }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询