473,382 Members | 1,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

modifying keypress

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
4 3119
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
"=?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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Danny | last post by:
I have a combo box look up and list items in a table, it is not bound. It works fine but how can I prevent the users from entering in there own data? i have an 'on change' event that when it...
3
by: Darryn Ross | last post by:
Hi, I am trying to catch the KeyPress event on my datagrid but it isn't working... i have also tried registering the handler with the event like this... dgGLBatch.KeyPress += new...
2
by: rege | last post by:
Hi, I have two applications developed in C# say A and B. When user presses key "L" with applicaition A active , it causes a keypress event which causes application B to run. Application A then...
1
by: Rene | last post by:
Hi, I am running is some problems with the KeyPreview and KeyPress events. The KeyPress event is only triggered when there this an focusable control on the form. When all controls are disabled...
4
by: Tom | last post by:
I have a VB.NET user control that I wrote - this control has three or four other controls on it (textbox, combobox, datetime picker, etc). Now, whenever the control is on a form and the user enters...
15
by: Adam J. Schaff | last post by:
I have noticed that if a user closes a form via pressing return (either while the OK button has focus or if AcceptButton is set to OK for the form) then the "ENTER" keypress event fires ON THE...
3
by: Fia | last post by:
Hi In Visual Basic 6 I could call keypress with an integer of a choosen key. For example I could call a textbox's keypress with the number 13 (for the enter key). But now in Visual Basic .Net I...
5
by: Henry Jones | last post by:
I am new to C# and wanted to capture the KeyPress for a textbox. I created some code as follows: private void textBox3_KeyPress(object sender, System.EventArgs e) { this.textBox2.Text =...
2
by: Tony Johansson | last post by:
Hello! I have created a Control that consist of a label and a textbox.I have called this class ctlLabelTextbox. public partial class ctlLabelTextbox : UserControl { .... } The class that I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.