Microsoft KB Archive/818363

= How to make the characters uppercase when you enter text in the TextBox by using Visual Basic .NET or Visual Basic 2005 =

Article ID: 818363

Article Last Modified on 11/26/2007

-

APPLIES TO


 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual Basic 2005

-



IN THIS TASK

 * SUMMARY
 * Make the Characters Uppercase by Using the CharacterCasing Property
 * Make the Characters Uppercase by Using Custom Code
 * REFERENCES



SUMMARY
This step-by-step article describes how to make the characters uppercase when you enter text in the TextBox by using Microsoft Visual Basic .NET or Microsoft Visual Basic 2005. The Visual Basic .NET or Visual Basic 2005 examples in this article describe how to use the CharacterCasing property in the designer to make the characters uppercase, and how to create custom code by using the KeyPress event to make the characters uppercase.

back to the top

Make the Characters Uppercase by Using the CharacterCasing Property
The TextBox has a CharacterCasing property that allows you to set the case of the characters that you type in the TextBox. By default, CharacterCasing is set to Normal. Therefore, the characters remain unchanged. For example, if you press the SHIFT+A key combination, an uppercase &quot;A&quot; is inserted in the TextBox. To make the characters uppercase by using the CharacterCasing property, follow these steps:
 * 1) Open Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
 * 2) On the File menu, point to New, and then click Project.
 * 3) Under Project Types, click to select Visual Basic Projects.

Note In Visual Studio 2005, click Visual Basic under Project Types.
 * 1) Under Templates, click to select Windows Application.

By default, Form1 is created.
 * 1) From the toolbox, drag a TextBox control to Form1.
 * 2) Right-click TextBox1, and then click Properties.
 * 3) In the Properties window, locate the CharacterCasing property, and then click to select Upper from the list.
 * 4) On the Debug menu, click Start.
 * 5) Type text in the TextBox.

All the characters are uppercase.

back to the top

Make the Characters Uppercase by Using Custom Code
 Open Visual Studio .NET or Visual Studio 2005. On the File menu, point to New, and then click Project. Under Project Types, click to select Visual Basic Projects.

Note In Visual Studio 2005, click Visual Basic under Project Types. Under Templates, click to select Windows Application.

By default, Form1 is created. From the toolbox, drag a TextBox control to Form1. On the View menu, click Code.  Add the following code to the KeyPress event of TextBox1: ' Operate only on lowercase characters, so that Backspace, Delete, Home, and others ' continue to work without interference.

If Char.IsLower(e.KeyChar) Then

'Convert to uppercase, and put at the caret position in the TextBox. TextBox1.SelectedText = Char.ToUpper(e.KeyChar)

e.Handled = True End If </li> On the Debug menu, click Start.</li> Type text in the TextBox.

All the characters are uppercase.</li></ol>

back to the top

<div class="references_section">