Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to VB.net. I want to use Richtextbox.Text. However, the error showing that Text is not part of Richtextbox. Upon checking further, I can see that it can be overridden using Overrides Property Text As String from the link
RichTextBox.Text Property (System.Windows.Forms)[^]

I would like to know how to add it to project or class. Please help. Thank you.

What I have tried:

Nothing has worked. Tried using Textrange and not working
Posted
Updated 3-Jul-18 3:57am
Comments
Ralf Meier 1-Jul-18 18:24pm    
Ähh ...sorry ... my Richtextbox has a Text-Property ...
Tell something more ...
Member 13857021 1-Jul-18 19:00pm    
Form2.RichTextBox1.Text = ""
Form2.RichTextBox1.Text = Form2.RichTextBox1.Text & textline(n) & vbCrLf

When I tried this, I am getting
'Text' is not a member of 'System.Windows.Control.RichTextbox'
Member 13857021 1-Jul-18 19:04pm    
Also, in another project, I can see that the same is implemented. However, it shows while hovering over text "Public Overrides Property Text As String"
Bernhard Hiller 2-Jul-18 3:54am    
In the title, you talk about "WPF", but then your code uses "Windows Forms" - they are different. With WPF, use MVVM pattern, do not access properties of UI elements directly, despite Microsoft still keeps that doable.
Member 13857021 2-Jul-18 11:42am    
As far as I know, it is WPF. I was adding all the features using coding only. I do not have good idea about the difference, however, the best I know is most of the features on toolbox is missing for WPF which is happening for me now. If any of you able to provide a contact detail, I can share the project with u.

1 solution

As Bernhard mentioned in the comments, you're looking at the documentation for the Windows Forms control. You need to look at the documentation for the WPF control, which doesn't have a Text property:

RichTextBox Class (System.Windows.Controls) | Microsoft Docs[^]

To get or set the text, you can use the code from this StackOverflow answer[^]:
VB.NET
' Set the text:
richTextBox1.Document.Blocks.Clear()
richTextBox1.Document.Blocks.Add(new Paragraph(new Run("The text...")))

' Read the text:
Dim text As String = New TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text

How to: Extract the Text Content from a RichTextBox | Microsoft Docs[^]
How to: Save, Load, and Print RichTextBox Content | Microsoft Docs[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900