By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,222 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

modifying keypress

P: n/a
Hi,
In VB6 you used to be able to modify keys as they were pressed in the
KeyPress event e.g. change it uppercase, remove certain characters etc.

How do I do this in .NET ?

Regards
Michael
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
In its simplest form:

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim myChar As String
myChar = e.KeyChar
TextBox1.Text += UCase(e.KeyChar)
e.Handled = True
End Sub

You will have to enter more code to handle/not handle othe keypress events
"Michael Green" <Mi**********@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.com...
Hi,
In VB6 you used to be able to modify keys as they were pressed in the
KeyPress event e.g. change it uppercase, remove certain characters etc.

How do I do this in .NET ?

Regards
Michael

Nov 21 '05 #2

P: n/a
"=?Utf-8?B?TWljaGFlbCBHcmVlbg==?=" <Mi**********@discussions.microsoft.com>
wrote in news:5B**********************************@microsof t.com:
Hi,
In VB6 you used to be able to modify keys as they were pressed in the
KeyPress event e.g. change it uppercase, remove certain characters etc.

How do I do this in .NET ?

Regards
Michael


Texboxes have a charactercasing property to only allow upper/lower case if
desired.
They have a keypress event, put code in there to handle the keypress, e.g.:
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e _
As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = "j" Then
'Tell the textbox the event has been handled
'and the character wont be displayed...
e.Handled = True
End If
End Sub

Nov 21 '05 #3

P: n/a
Sorry, should of been:

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles

TextBox1.KeyPress
TextBox1.Text += UCase(e.KeyChar)
e.Handled = True

End Sub

"DazedAndConfused" <Ac********@yahoo.com> wrote in message
news:L6***********@twister.nyroc.rr.com...
In its simplest form:

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim myChar As String
myChar = e.KeyChar
TextBox1.Text += UCase(e.KeyChar)
e.Handled = True
End Sub

You will have to enter more code to handle/not handle othe keypress events
"Michael Green" <Mi**********@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.com...
Hi,
In VB6 you used to be able to modify keys as they were pressed in the
KeyPress event e.g. change it uppercase, remove certain characters etc.

How do I do this in .NET ?

Regards
Michael


Nov 21 '05 #4

P: n/a
Thanks for that. Why is it necessary to call the event from within itself ?

"DazedAndConfused" wrote:
Sorry, should of been:

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles

TextBox1.KeyPress
TextBox1.Text += UCase(e.KeyChar)
e.Handled = True

End Sub

"DazedAndConfused" <Ac********@yahoo.com> wrote in message
news:L6***********@twister.nyroc.rr.com...
In its simplest form:

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim myChar As String
myChar = e.KeyChar
TextBox1.Text += UCase(e.KeyChar)
e.Handled = True
End Sub

You will have to enter more code to handle/not handle othe keypress events
"Michael Green" <Mi**********@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.com...
Hi,
In VB6 you used to be able to modify keys as they were pressed in the
KeyPress event e.g. change it uppercase, remove certain characters etc.

How do I do this in .NET ?

Regards
Michael



Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.