How to make the characters uppercase when you enter text in the TextBox by using Visual Basic .NET or Visual Basic 2005 (818363)
The information in this article applies to:
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual Basic 2005
SUMMARYThis 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 topMake the Characters Uppercase by Using the CharacterCasing PropertyThe 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 "A" is inserted in the TextBox. To make the characters uppercase by using the CharacterCasing property, follow these steps: - Open Microsoft Visual Studio .NET or Microsoft 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.
- Right-click TextBox1, and then click
Properties.
- In the Properties window, locate the
CharacterCasing property, and then click to select
Upper from the list.
- On the Debug menu, click
Start.
- Type text in the TextBox.
All the
characters are uppercase. back to the
topMake 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 - On the Debug menu, click
Start.
- Type text in the TextBox.
All the
characters are uppercase. back to the
topREFERENCESFor more information, visit the following MSDN Web
sites: back to the
top
Modification Type: | Minor | Last Reviewed: | 10/3/2006 |
---|
Keywords: | kbvs2005swept kbvs2005applies kbHOWTOmaster kbconvert kbWindowsForms kbCtrl kbControl kbhowto KB818363 kbAudDeveloper |
---|
|