473,395 Members | 1,532 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,395 software developers and data experts.

Keypress Event not Firing for enter key

I have 2 mdi childforms which are database input forms. Each form has the
usual add/delete/edit/save buttons and a few textboxes. I capture the
keypress events on the textboxes to allow only numbers and I also capture the
Enter key to move focus to the next control. The forms work fine if only
one form is opened. If both forms are opened and I then switch to the form
that was opened first the keypress event does not capture the enter key but
the the other characters work. The keypreview property is set to true for
all forms. I am at a dead end here and cannot figure it out, can someone
please help.

keypress code:

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

Dim Numbers As String = "1234567890" + Microsoft.VisualBasic.ChrW(13) _
+ Microsoft.VisualBasic.ChrW(8)

If InStr(Numbers, e.KeyChar) = 0 Then
MessageBox.Show("Invalid character, Only numbers are allowed!",
"Input Error", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
e.Handled = True
End If

If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
SendKeys.Send("{TAB}")
e.Handled = True
End If
End Sub

Nov 21 '05 #1
3 3631
I forgot to mention that all fields are disabled when the form is loaded and
enabled only when the add/edit buttons are clicked.
Nov 21 '05 #2
"JAG711" <JA****@discussions.microsoft.com> wrote in message
news:37**********************************@microsof t.com...
I capture the keypress events on the textboxes to allow only numbers
and I also capture the Enter key to move focus to the next control.
The forms work fine if only one form is opened. If both forms are
opened and I then switch to the form that was opened first the
keypress event does not capture the enter key but the the other
characters work.


Does either Form have the AcceptButton property set?
This seems to "steal" the Enter keypress on that Form.

HTH,
Phill W.
Nov 21 '05 #3
No none of the forms have the AcceptButton property set?
"Phill. W" wrote:

Does either Form have the AcceptButton property set?
This seems to "steal" the Enter keypress on that Form.

HTH,
Phill W.

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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...
0
by: Steph. | last post by:
Hi, I have made a new custom TextBox control to enable ENTER and TAB keys to be trapped in the "KeyPress" and "KeyDown" Events. to do that I have overridden the "IsInputKey" property in my...
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: Nikolay Evseev | last post by:
Hi, I am trying to trace down the Enter key in my Form.KeyPress event handler. The KeyPreview property is set to false, so I'd assume that all key presses should go through my form's KeyPress...
1
by: Jim Hubbard | last post by:
Why isn't the Keypress event of the System.Windows.Form.ToolStripComboBox triggered by hitting the Enter key? I cannot trap Keys.Enter or Keys.Return in the Keypress event.
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 =...
1
by: bigijoseph | last post by:
Please help : page load event is not firing. -------------------------------------------------------------------------------- Hi, I am a new to .net. I am trying to learn it. I tried the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.