|
-
Nov 15th, 2018, 01:21 PM
#1
Thread Starter
Junior Member
[RESOLVED] ToUpper destroying Richtextbox format.
I am using a ToUpper statement on a RichTextBox and I have found it is destroying the color formatting.
This is the output of the RTB before the ToUpper statement
Code:
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}
{\colortbl ;\red255\green255\blue255;\red0\green255\blue0;}
\viewkind4\uc1\pard\cf1\f0\fs192 There are a great number of things you \cf2\bullet\cf1 cannot do with a Declare statement. \par
}
This is the statement I am using
Code:
RichTextBox1.Text = RichTextBox1.Text.ToUpper()
This is the output after the ToUpper statement
Code:
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}
{\colortbl ;\red255\green255\blue255;}
\viewkind4\uc1\pard\cf1\f0\fs192 THERE ARE A GREAT NUMBER OF THINGS YOU \bullet CANNOT DO WITH A DECLARE STATEMENT. \par
}
Does anyone have any thoughts on why this happens and how to solve it?
Thanks
-
Nov 15th, 2018, 05:26 PM
#2
Thread Starter
Junior Member
Re: ToUpper destroying Richtextbox format.
Seems any manipulation of RichTextBax1.Text harms the formatting. Typing in the control works fine but replacing or inserting a character to the RichTextBox1.Text causes formatting to be lost. This makes me wonder if I need to manipulate the RichTextBox1.Rtf somehow. Looking at the value of RichtextBox1.Rtf I see most of the beginning formatting values are within {}. All the other formatting items within the actual text are preceded with a \. If there is a \ in the actual text then the RichTextBox1.Rtf contains \\. If a { is used as part of the actual text the RichTextBox1.Rtf contains a \{. A space seems to indicate the end of a formatting command in the RichTextBox1.Rtf.
Has anyone tried manipulating the RichTextBox1.Rtf? I hesitate to start down that path if its a dead end.
-
Nov 15th, 2018, 06:36 PM
#3
Re: ToUpper destroying Richtextbox format.
The RichTextBox does have its limitations as an RTF editor. I suspect that what you might have to do is select the text by portions based on formatting like colour, etc, and then set the SelectedText with the result of ToUpper so as not to disturb the other formatting. I've seen other solutions to RTF editing but none free I'm afraid.
-
Nov 16th, 2018, 11:33 AM
#4
Re: ToUpper destroying Richtextbox format.
what if you manipulate the .SelectionText rather than the .Text? Would that make a difference? Set the .SelectionStart = 0, .SelectionLength = rtf.Text.Length, .SelectionText = .SelectionText.ToUpper()
Not sure if it'll work, and don't have a way to test it at the moment. Would be easier than trying to manipulate it from the RTF side though.
-tg
-
Nov 17th, 2018, 11:12 AM
#5
Thread Starter
Junior Member
Re: ToUpper destroying Richtextbox format.
I did try using selected text one character at a time. I walked the rtb.text until I found the first lower case character. Selected that character but as soon as I did toupper on selectedtext I lost my font color assignments to other text in the rtb.
-
Nov 24th, 2018, 05:13 PM
#6
Thread Starter
Junior Member
Re: ToUpper destroying Richtextbox format.
Well strange enough this works. It changes the case to upper in the Richtextbox without destroying the formatting. I have no clue why it works.
Code:
Private Sub chkCaps_CheckedChanged(sender As Object, e As EventArgs) Handles chkCaps.CheckedChanged
'ToDo Uppercase all text without harming the formatting.
If chkCaps.Checked Then
Dim sTemp As String = RichTextBox1.Rtf
sTemp = Strings.Right(sTemp, sTemp.Length - 7)
RichTextBox1.Rtf = "{\rtf1\" & sTemp.ToUpper
End If
End Sub
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|