Already found a way to resolve this:
Public Shared Sub TrimRichTextBox(ByRef RichTextControl As RichTextBox, _
Optional ByVal LeadingSpaces As Boolean = True, _
Optional ByVal TrailingSpaces As Boolean = True)
Try
If LeadingSpaces Then
Do While RichTextControl.Text.StartsWith(" ")
RichTextControl.SelectionStart = 0
RichTextControl.SelectionLength = 1
RichTextControl.SelectedText = ""
Loop
End If
If TrailingSpaces Then
Do While RichTextControl.Text.EndsWith(" ")
RichTextControl.SelectionStart = RichTextControl.Text.Length - 1
RichTextControl.SelectionLength = 1
RichTextControl.SelectedText = ""
Loop
End If
Catch ex As Exception
Throw New Exception(System.Reflection.MethodInfo.GetCurrentM ethod.Name, ex)
End Try
End Sub
Hello,
In my code I use the following command:
me.richtextbox1.text = me.richtextbox1.text.trim
By doing this I lose al my text formatting, it seems that by setting the text property of a richtextbox you lose al the formatting.
Any idea how I can remove the leading and trailing spaces in a text without losing the rtf formatting?
Thanks in advance.
David