jag711 Posted March 31, 2005 Posted March 31, 2005 :confused: 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. Note that all fields are disabled when the form is loaded and enabled only when the add/edit buttons are clicked. 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 Quote
Rothariger Posted March 31, 2005 Posted March 31, 2005 look if you can doit with keydown, i must to make it with it... salute!!! Quote
*Experts* DiverDan Posted March 31, 2005 *Experts* Posted March 31, 2005 usually you'd specify a textbox for this type of key press restriction, not the form. Here's an example: 'Positive Whole Numbers and Backspace Only - with leading 0 Private Sub PositiveWholeNumbersWithZero_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If AscW(e.KeyChar) = 8 Then 'backspace e.Handled = False ElseIf AscW(e.KeyChar) >= 47 And AscW(e.KeyChar) < 58 Then e.Handled = False Else : e.Handled = True End If End Sub Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
jag711 Posted April 1, 2005 Author Posted April 1, 2005 I have tried the code samples above but it does not make a difference. The code works when the form is loaded but the problem appears only when I switch forms. Definately something to do with MDI forms :confused: Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.