我看到如何在 WPF 中设置富文本框,方法在 RichTextBox Class。
但我想像之前在 Windows Forms 一样将其文本保存到数据库中。
string myData = richTextBox.Text;
dbSave(myData);
我该怎么做?
我看到如何在 WPF 中设置富文本框,方法在 RichTextBox Class。
但我想像之前在 Windows Forms 一样将其文本保存到数据库中。
string myData = richTextBox.Text;
dbSave(myData);
我该怎么做?
在MSDN的RichTextBox参考文献底部,有一个链接指向如何从RichTextBox提取文本内容
它将看起来像这样:
public string RichTextBoxExample()
{
RichTextBox myRichTextBox = new RichTextBox();
// Create a FlowDocument to contain content for the RichTextBox.
FlowDocument myFlowDoc = new FlowDocument();
// Add initial content to the RichTextBox.
myRichTextBox.Document = myFlowDoc;
// Let's pretend the RichTextBox gets content magically ...
TextRange textRange = new TextRange(
// TextPointer to the start of content in the RichTextBox.
myRichTextBox.Document.ContentStart,
// TextPointer to the end of content in the RichTextBox.
myRichTextBox.Document.ContentEnd
);
// The Text property on a TextRange object returns a string
// representing the plain text content of the TextRange.
return textRange.Text;
}