473,695 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_KeyP ress(ByVal sender As System.Object, ByVal e As
System.Windows. Forms.KeyPressE ventArgs) Handles editUserID.KeyP ress

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

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

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

Nov 21 '05 #1
3 3649
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****@discuss ions.microsoft. com> wrote in message
news:37******** *************** ***********@mic rosoft.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.

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.

Phill W.

Nov 21 '05 #4

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

Similar topics

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 KeyPressEventHandler(dgGLBatch_KeyPress); but nothing changed. I was wondering wether a custom table and column style might have an effect on how this works???
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 new control (derived from the TextBox control)(see code below). I can now manage the KeyPress/Down event raised by TAB and ENTER keys, but I have one problem : A sound (ding) is played by my computer every time I press the TAB or ENTER key in...
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 the Form.KeyPress event does not trigger anymore. A way to 'solve' this is to set the focus to the form, but during testing it happens ofter the keypress event is not getting triggered on keys like
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 anything into the textbox (for instance) I trap the keypress event to handle some stuff (i.e. if it is an enter key, etc). Now, once I am done with handling the keypress event for the textbox, I then need to pass that keypress event BACK to the...
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 CALLING FORM! This is very bad for me, because in my application, Form1 responds to an ENTER keypress by calling Form2. If the user closes Form2 via an ENTER, then Form1 just reopens it again, kind of trapping the user in Form2 (they can still close...
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 event handler, right? Ok. If the focus is set to any other control than a button, then the above event handler fires, but if the focus is on a button, then I've no way to know that the Enter key has been pressed or not, because in that case pressing...
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.
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 = sender.ToString();
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 following code to execute. But the page load event is not firing. I tried , the same function rewriten in C#, then page load event worked absolutely fine. I dont know why the page load event is not firing in VB.net . Could some one try please try my same...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.