Hello all,
I have encountered an interesting issue that I can not seem to resolve.
I have a textbox and a rtfbox on one form that the enter key is being ignored. When I create a new textbox on that form the problemoccurs thereas well. However, when I create a new form in the same project, the enter key starts working with any multiline text boxes. I deleted all code at the form level thathandles keyboard processing and set keypreview to false but the problem does not go away. I verified multiline is set to true on both the textbox and the rtfbox. I even tried adding code to the key_up event for the form that would test for the return key and the event does see it.
So, I am a complete loss as to what could could be causing this issue. Any help would be apreciated. - Changed TypeAland LiMSFT, ModeratorMonday, September 07, 2009 9:49 AMNo reply
- Changed TypeAland LiMSFT, ModeratorTuesday, September 08, 2009 1:55 AMReply
-
| | cbGifford Monday, August 31, 2009 6:02 AM | Hi cbGifford,
I have tested the code and found that the KeyDown/KeyUp event of the RichTextBox/TextBox is not fired, but the Click event of the btnAddIngredient button is fired. Please feel free to tell me if this is not the issue you met.
The root cause of this issue is that the AcceptButton property of the form is set to btnAddIngredient, so when we press the Enter key, the click event of the btnAddIngredient button would be fired and the Enter key would not be received by other controls on the form.
Based on my understanding, you want to have the user be able to enter ‘\n�if the current control is a RichTextBox/TextBox and its Multiline property is true, otherwise the click event handler of the default button would be fired. To meet this needs, we need to set the AcceptButton property of the form to none and add some code in the beginning of the KeyUp event handler of the form. This is a code snippet:
Private Sub frmCookbook_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
'Cope with the enter.
If e.KeyCode = Keys.Enter Then
Dim textCtrl As TextBoxBase = TryCast(Me.ActiveControl, TextBoxBase)
'If the current control is not of type TextBoxBase and it is not multiline,
'the click event of the default button would be fired.
If textCtrl Is Nothing Then
btnAddIngredient_Click(btnAddIngredient, Nothing)
Else
If Not textCtrl.Multiline Then
btnAddIngredient_Click(btnAddIngredient, Nothing)
End If
End If
End If
'Other code
End Sub
Let me know if this does not help. Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread. - Marked As Answer bycbGifford Tuesday, September 15, 2009 7:09 PM
-
| | Aland Li Tuesday, September 15, 2009 7:18 AM | Hi Aland,
Thank you so very much! That solved the issue!
To summarize:
The acceptbutton property when set intercepts the enter key from the keyboard event and then fires the click event for the button. This effectively disables all multiline text boxes on the form from being able to process the enter key.
Again, thank you for your assistance. - Marked As Answer bycbGifford Tuesday, September 15, 2009 8:09 PM
-
| | cbGifford Tuesday, September 15, 2009 7:17 PM | Hi cbGifford,
Could you please post the code snippet of the error form including .Designer.cs? We need code to reproduce the error.
From my experience, you need to check these items: 1.Does this form derive from another parent form? If so, we need to check the code in parent form. 2. Do you override these methods: ProcessCmdKey, ProcessDialogKey, ProcessKeyMessage, ProcessKeyPreview? If so, you might ignore the Enter key in these methods.
Regards, Aland Li Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread. | | Aland Li Tuesday, September 01, 2009 11:26 AM | Hi Aland,
I am not overriding any methods and the form is not derived from another form. I searched both the form's code as well as the designer code for the mentioned methods and they are not present. Between the two forms, there is over 5,000 lines of code. I got an error when I tried pasting them as two code blocks in this reply.
I will try to make two separate replies with the code from each file that you requested.
I am unable to add the code, I get an msgbox that has a yellow triangle with no message in it. I am assuming it is to big. The designer file is 3800 lines and my code is over 1400 lines. Is there a paticular section that you would like to see or is there a way I can add the two files as an attachment to the thread?
Thank you for any help you can give me on this. | | cbGifford Tuesday, September 01, 2009 8:48 PM | Hi cbGifford,
Have you solved your issue? Could you please provide more information?
Regards, Aland Li Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread. | | Aland Li Friday, September 04, 2009 3:42 AM | Hi,
We are changing the issue type to “General Discussion�because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question�by opening the Options list at the top of the post window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread. | | Aland Li Monday, September 07, 2009 9:49 AM | Change it all you want since you are unable to answer a simple question. I tried uploading the form's code and was unable to. I posted that in the message that I sent to you. And if you did not know, it is a national holiday today and yo uasked a question on Friday
Microsoft, extremely unprofessional since you are unable to read. I will muddle through this without your help. | | cbGifford Monday, September 07, 2009 8:56 PM | Hi cbGifford,
Sorry for not answering the question below at first: I am unable to add the code, I get an msgbox that has a yellow triangle with no message in it. I am assuming it is to big. The designer file is 3800 lines and my code is over 1400 lines. Is there a paticular section that you would like to see or is there a way I can add the two files as an attachment to the thread?
Could you please email the code to me: alala666888@hotmail.com.
Regards, Aland Li Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread. | | Aland Li Tuesday, September 08, 2009 1:59 AM | check if u have supressed enter key in keydown event..
| | Bharath kumar Y.S Wednesday, September 09, 2009 9:17 AM | Hi cbGifford,
Sorry for not answering the question below at first: I am unable to add the code, I get an msgbox that has a yellow triangle with no message in it. I am assuming it is to big. The designer file is 3800 lines and my code is over 1400 lines. Is there a paticular section that you would like to see or is there a way I can add the two files as an attachment to the thread?
Could you please email the code to me: alala666888@hotmail.com.
Regards, Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Thank you, I've sent the files that you requested to your email address. While the form has about 100 text boxes on it, there is only two that are multi-line. One on the tools tab and the other is an rtftextbox on the Directions tab | | cbGifford Wednesday, September 09, 2009 10:14 PM | check if u have supressed enter key in keydown event..
Thank you for you suggestion but there is no key_down event. | | cbGifford Wednesday, September 09, 2009 10:15 PM | Hi cbGifford,
Sorry for the late reply. I got the email, but I can only receieve the .resx file. The other two files are prevented for some security reasons. Could you please package the files via Zip or Rar and send it again?
Regards, Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread. | | Aland Li Thursday, September 10, 2009 2:47 AM | Did not get the alert for some reason that you responded, sorry. I sent them in a zip file just now | | cbGifford Sunday, September 13, 2009 9:22 PM | Hi cbGifford,
Sorry for the late reply. I have received the code, but there are too many classes cannot be found in the code, so I cannot compile it. Could you please package the core code to a project and email the small project to me?
Regards, Aland Li Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread. | | Aland Li Monday, September 14, 2009 4:03 AM | Hi Aland,
I zipped up the whole project and just sent it off to you. I appreciate any assistance you can give me here,
Chris | | cbGifford Monday, September 14, 2009 7:44 PM | Hi cbGifford,
I have tested the code and found that the KeyDown/KeyUp event of the RichTextBox/TextBox is not fired, but the Click event of the btnAddIngredient button is fired. Please feel free to tell me if this is not the issue you met.
The root cause of this issue is that the AcceptButton property of the form is set to btnAddIngredient, so when we press the Enter key, the click event of the btnAddIngredient button would be fired and the Enter key would not be received by other controls on the form.
Based on my understanding, you want to have the user be able to enter ‘\n�if the current control is a RichTextBox/TextBox and its Multiline property is true, otherwise the click event handler of the default button would be fired. To meet this needs, we need to set the AcceptButton property of the form to none and add some code in the beginning of the KeyUp event handler of the form. This is a code snippet:
Private Sub frmCookbook_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
'Cope with the enter.
If e.KeyCode = Keys.Enter Then
Dim textCtrl As TextBoxBase = TryCast(Me.ActiveControl, TextBoxBase)
'If the current control is not of type TextBoxBase and it is not multiline,
'the click event of the default button would be fired.
If textCtrl Is Nothing Then
btnAddIngredient_Click(btnAddIngredient, Nothing)
Else
If Not textCtrl.Multiline Then
btnAddIngredient_Click(btnAddIngredient, Nothing)
End If
End If
End If
'Other code
End Sub
Let me know if this does not help. Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread. - Marked As Answer bycbGifford Tuesday, September 15, 2009 7:09 PM
-
| | Aland Li Tuesday, September 15, 2009 7:18 AM | Hi Aland,
Thank you so very much! That solved the issue!
To summarize:
The acceptbutton property when set intercepts the enter key from the keyboard event and then fires the click event for the button. This effectively disables all multiline text boxes on the form from being able to process the enter key.
Again, thank you for your assistance. - Marked As Answer bycbGifford Tuesday, September 15, 2009 8:09 PM
-
| | cbGifford Tuesday, September 15, 2009 7:17 PM |
|