Force Uppercase
-
Friday, October 21, 2005 1:37 PMI have a textbox into which data is keyed.
I want to be able to have the keys entered set to upper case before they appear in the textbox.
I dont want the user to have to use the shift key. how can i do this?
Can i do something inside the KeyDown or KeyPressed event that will convert them to uppercase
All Replies
-
Friday, October 21, 2005 2:03 PM
Add this code to the KeyPress event:
if (char.IsLower(e.KeyChar))
{
e.KeyChar = char.ToUpper(e.KeyChar);
}
- Proposed As Answer by Morphlin Tuesday, October 16, 2012 5:19 PM
-
Friday, October 21, 2005 2:09 PMI have tried this, however it says the KeyChar is ReadOnly
Private Sub txtBTAddr1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtBTAddr1.KeyPress
If Char.IsLower(e.KeyChar) Then
e.KeyChar = Char.ToUpper(e.KeyChar)
End If
End Sub
-
Friday, October 21, 2005 2:14 PMI've tried it on a regular WinForms app, in VS2005.
I don't know, it might be a CF or a version problem...
-
Friday, October 21, 2005 2:26 PM
Found a solution
Add the following code into the textbox's keyup event
txtBTAddr1.Text = txtBTAddr1.Text.ToUpper
txtBTAddr1.Select(txtBTAddr1.Text.Length, 0)
-
Wednesday, August 30, 2006 12:36 AM
Not a good solution...
You're converting all the text to upper case. This makes caracter insertion impossible. The cursor won't move....
Keychar shound't be read-only!!!!
-
Thursday, August 31, 2006 12:09 PM
hello Barry,
Maybe you could use the OpenNETCF.Windows.Forms.TextBox2 control.
It has a property that configures the character casing that should be used:
textBox.CharacterCasing = CharacterCasing.Upper;
Greetings,
Peter Vrenken
- Proposed As Answer by Ash28 Monday, September 10, 2012 12:26 PM
-
Thursday, August 31, 2006 12:22 PM
or you could just make whatever the user types in, to uppercase after they press a continue button or something.
Dim theString as string = Me.theTextBox.Text.ToUpper()
-
Friday, March 02, 2007 3:10 PMAdd the below code in a css file and add it to your project. Apply this css to the control say a textbox like :
<asp:TextBox ID="txtSurname" CssClass="TextBoxUpperCase" runat="server" ><asp:TextBox>
.TextBoxUpperCase
{
text-transform: uppercase;
color: black;
}
This will convert the case to upper as you type in the control. Cheers! -
Wednesday, May 30, 2007 3:02 PM
e.KeyChar is readonly as passed from the base control. The following works in VB.NET:
If Char.IsLower(e.KeyChar) Thene.Handled =
TrueSendKeys.Send(
Char.ToUpper(e.KeyChar)) End If -
Wednesday, May 20, 2009 2:52 PMThis works sucessfuly..
Rupesh Kumar



Friday, March 02, 2007 3:10 PM
0 votesVote As HelpfulAdd the below code in a css file and add it to your project. Apply this css to the control say a textbox like :
<asp:TextBox ID="txtSurname" CssClass="TextBoxUpperCase" runat="server" ><asp:TextBox>
.TextBoxUpperCase
{
text-transform: uppercase;
color: black;
}
This will convert the case to upper as you type in the control.
Cheers!
thks lot!! -
Friday, September 16, 2011 4:52 AM
Thank for valuable information..
great man
- Proposed As Answer by muneer uc Friday, September 16, 2011 4:52 AM
-
Friday, June 08, 2012 10:22 PM
I think this is the easiest way:
Title Make a TextBox convert letters to upper case in VB.NET Description This example shows how to make a TextBox convert letters to upper case in VB.NET by setting the control's CharacterCasing property. Keywords TextBox, lower case, VB.NET Categories Controls, VB.NET When the form loads, it sets the TextBox's CharacterCasing property to Upper. Private Sub Form1_Load(ByVal sender As System.Object, ByVal _ e As System.EventArgs) Handles MyBase.Load ' Set the TextBox's character casing. TextBox2.CharacterCasing = CharacterCasing.Upper End Sub -
Monday, January 07, 2013 9:43 AM
I know this thread is out dated but I am writing this just to help if anyone struck up with the same issue.
Yes,We can handle it in KeyPressEvent.I was facing same issue and it fixed it as below.
1. Created a Custom contol and overridden the keypress event.
Below is the code snippet.
public partial class myTextBox : TextBox
{
public myTextBox ()
{
InitializeComponent();
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
int start = SelectionStart;
if (SelectionLength > 0)
SelectedText =
string.Empty;
if (Text.Length == MaxLength)
{
e.Handled =
true;
}
else
{
if (char.IsLower(e.KeyChar))
{
Text = Text.Insert(start,
char.ToUpper(e.KeyChar).ToString());
SelectionStart = start + 1;
e.Handled =
true;
}
base.OnKeyPress(e);
}
}
}

