views:

3885

answers:

4

Hi,

I am trying to set/get the text of my RichTextBox, but Text is not among list of its properties when I want to get test.Text...

I am using code behind in C# (.net framework 3.5 SP1)

RichTextBox test = new RichTextBox(); cannot have test.Text(?)

Do you know how come it can be possible ?

thanks,

A: 

There surely is a Text property to the RichTextBox control. Do you get a compilation error when you try to access it, or something else?

The Text property gets and sets the plain text contained in the control (that is, without formatting). There is also an Rtf property, which takes and returns RTF. That may be what you want or expect.

Michael Petrotta
A: 

According to this it does have a Text property

http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox_members.aspx

You can also try the "Lines" property if you want the text broken up as lines.

ferrari fan
This is WPF, not Win Forms.
subkamran
+2  A: 

There was a confusion between RichTextBox in System.Windows.Forms and in System.Windows.Control

I am using the one in the Control as I am using WPF. In there, there is no Text property, and in order to get a text, I should have used this line:

string myText = new TextRange(transcriberArea.Document.ContentStart, transcriberArea.Document.ContentEnd).Text;

thanks

+1  A: 

The WPF RichTextBox has a Document property for setting the content a la 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;

You can just use the AppendText method though if that's all you're after.

Hope that helps.

Stimul8d