string myText = new TextRange(transcriberArea.Document.ContentStart, transcriberArea.Document.ContentEnd).Text;
谢谢
8
WPF RichTextBox具有 Document 属性,用于将内容设置为MSDN:
// Create a FlowDocument to contain content for the RichTextBox.
FlowDocument myFlowDoc = new FlowDocument();
// Add paragraphs to the FlowDocument.
myFlowDoc.Blocks.Add(new Paragraph(new Run("Paragraph 1")));
myFlowDoc.Blocks.Add(new Paragraph(new Run("Paragraph 2")));
myFlowDoc.Blocks.Add(new Paragraph(new Run("Paragraph 3")));
RichTextBox myRichTextBox = new RichTextBox();
// Add initial content to the RichTextBox.
myRichTextBox.Document = myFlowDoc;
你可以使用 AppendText 方法,如果's all you'之后 .
希望有所帮助 .
8
string GetString(RichTextBox rtb)
{
var textRange = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd);
return textRange.Text;
}
4
WPF RichTextBox控件中没有 Text 属性 . 这是获取所有文本的一种方法:
TextRange range = new TextRange(myRTB.Document.ContentStart, myRTB.Document.ContentEnd);
string allText = range.Text;
12
RichTextBox rtf = new RichTextBox();
System.IO.MemoryStream stream = new System.IO.MemoryStream(ASCIIEncoding.Default.GetBytes(yourText));
rtf.Selection.Load(stream, DataFormats.Rtf);
要么
rtf.Selection.Text = yourText;
-9
使用两种扩展方法,这变得非常简单:
public static class Ext
{
public static void SetText(this RichTextBox richTextBox, string text)
{
richTextBox.Document.Blocks.Clear();
richTextBox.Document.Blocks.Add(new Paragraph(new Run(text)));
}
public static string GetText(this RichTextBox richTextBox)
{
return new TextRange(richTextBox.Document.ContentStart,
richTextBox.Document.ContentEnd).Text;
}
}
11 回答
到 set RichTextBox文本:
to get RichTextBox文本:
在System.Windows.Forms和System.Windows.Control中的RichTextBox之间存在混淆
我正在使用控件中的那个,因为我正在使用WPF . 在那里,没有Text属性,为了获得文本,我应该使用这一行:
谢谢
WPF RichTextBox具有
Document
属性,用于将内容设置为MSDN:你可以使用
AppendText
方法,如果's all you'之后 .希望有所帮助 .
WPF RichTextBox控件中没有
Text
属性 . 这是获取所有文本的一种方法:要么
使用两种扩展方法,这变得非常简单:
如何做到以下几点:
“Extended WPF Toolkit”现在提供带有Text属性的richtextbox .
您可以以不同的格式(XAML,RTF和纯文本)获取或设置文本 .
这是链接:Extended WPF Toolkit RichTextBox
在我的情况下,我不得不将RTF文本转换为纯文本:我在GiangLP答案中所做的(使用Xceed WPF Toolkit);并在扩展方法中设置我的代码:
根据它,它确实有一个Text属性
http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox_members.aspx
如果您希望将文本拆分为线条,也可以尝试“线条”属性 .