RichTextBox Question

icemanind

Member
Joined
Mar 20, 2008
Messages
12
Programming Experience
5-10
I have a multiline RichTextBox control on my form and what I want to do is, whenever someone hits enter, I want the line to automatically convert to all capital letters.

Similar to how, in Visual Studio, if you enter a line of Visual Basic code, the IDE will automatically make the VB.NET keywords proper-case.


any ideas on how to do this?
 
Use the Key_Press event to handle the 'hits the enter button:

If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Enter) Then
Label1.Text = StrConv(TextBox1.Text, VbStrConv.ProperCase)
End If

I have not tried this with a RichTextBox with diff. formatting, but give it a shot.
 
I'm overriding the OnKeyDown event and capturing the enter keystroke. That part I got down. I am using the following code:

VB.NET:
Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
        MyBase.OnKeyDown(e)
        If e.KeyCode = Keys.Enter Then
            Me.Text = Me.Text.ToUpper
        End If
End Sub

The problem is, it wants to put the cursor back on the first line...So when I hit enter, the cursor moves up to the top...then my carriage return is printed. Anyone know how to get around this?
 
Get the current SelectionStart index before you change the text content, set the same SelectionStart index afterwards.

If you need a multi-line textbox with all characters in upper case you can also use the TextBox control and set Multiline and CharacterCasing properties.
 
Back
Top