Restricting a multiline text box
-
I have done some searching and can't find the answer to this one anywhere. I have a multiline textbox on a form that shows 2 lines of text on the form. I have restricted it to 200 chars because the report page that it prints on can display 200 chars in 2 lines. My problem is users can press return as many times as they want and put as many lines of text in the box as is possible before they use the 200 chars. Since the report will recognize a CRLF character and move the text to the next line if they put more than 2 lines of text in the multiline text box only 2 of those lines of text will print no matter what. They are wanting to restrict the data entry box so that only 2 lines of text can be entered even if the character count is less that 200. Is there a way to do this? I'm coding in VB.net with Visual Studio 2005 and using Crystal Reports XI for my report. I can't manipulate the report side of things to print more than 2 lines because the way the report is laid out there is no room. Thanks in advance to anyone who can help. Judy
-
I have done some searching and can't find the answer to this one anywhere. I have a multiline textbox on a form that shows 2 lines of text on the form. I have restricted it to 200 chars because the report page that it prints on can display 200 chars in 2 lines. My problem is users can press return as many times as they want and put as many lines of text in the box as is possible before they use the 200 chars. Since the report will recognize a CRLF character and move the text to the next line if they put more than 2 lines of text in the multiline text box only 2 of those lines of text will print no matter what. They are wanting to restrict the data entry box so that only 2 lines of text can be entered even if the character count is less that 200. Is there a way to do this? I'm coding in VB.net with Visual Studio 2005 and using Crystal Reports XI for my report. I can't manipulate the report side of things to print more than 2 lines because the way the report is laid out there is no room. Thanks in advance to anyone who can help. Judy
1. Count the number of CRs in the textbox.text and beat on the user if there is more than 1 2. Use the keydown/up events to interactively manage the characters typed into the textbox.
Never underestimate the power of human stupidity RAH
-
1. Count the number of CRs in the textbox.text and beat on the user if there is more than 1 2. Use the keydown/up events to interactively manage the characters typed into the textbox.
Never underestimate the power of human stupidity RAH
-
1. Count the number of CRs in the textbox.text and beat on the user if there is more than 1 2. Use the keydown/up events to interactively manage the characters typed into the textbox.
Never underestimate the power of human stupidity RAH
-
Ok, I've counted the number of returns in the box and can display a message but if I tell it to supress the keystroke in the keydown event it still enters the return in the box. How do I stop the return from being entered? Thanks, Judy
-
Ok, I've counted the number of returns in the box and can display a message but if I tell it to supress the keystroke in the keydown event it still enters the return in the box. How do I stop the return from being entered? Thanks, Judy
Try the keyup and test, keydown happens BEFORE the key is entered. I don't think you can actually suppress the enter key from being pressed. I have always found interactive management of what the user does to be painful, I almost always let them do what they want and then clean up after, probably using the on leave event.
Never underestimate the power of human stupidity RAH
-
Try the keyup and test, keydown happens BEFORE the key is entered. I don't think you can actually suppress the enter key from being pressed. I have always found interactive management of what the user does to be painful, I almost always let them do what they want and then clean up after, probably using the on leave event.
Never underestimate the power of human stupidity RAH
Actually it is suppressing the keystroke on the keydown event. I created a derived class and added the count returns as a property and put the keydown event code override in the class and it works well. I also added an event for the text change to keep track of whether or not they go in and delete text and/or a return so that the count will remain accurate while they are working in the text box. Private Sub MyTextBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown If (e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Return) Then If Me.CRLFCnt > 0 Then e.SuppressKeyPress = True Else Me.CRLFCnt += 1 End If End If End Sub As I said it took me awhile to figure it out and I had a message box popping up to tell them they had tried to put in too many lines and for some reason that caused the suppress method not to work. I tried putting the message box in the keyup event but then it just looped if you hit return on the 'OK' button. If you clicked it with the mouse it went away but we try to code things so the users don't have to take their hands from the keyboard any more than possible. Thanks for your help it did point me in the right direction and saved me a lot of time. Judy
-
Actually it is suppressing the keystroke on the keydown event. I created a derived class and added the count returns as a property and put the keydown event code override in the class and it works well. I also added an event for the text change to keep track of whether or not they go in and delete text and/or a return so that the count will remain accurate while they are working in the text box. Private Sub MyTextBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown If (e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Return) Then If Me.CRLFCnt > 0 Then e.SuppressKeyPress = True Else Me.CRLFCnt += 1 End If End If End Sub As I said it took me awhile to figure it out and I had a message box popping up to tell them they had tried to put in too many lines and for some reason that caused the suppress method not to work. I tried putting the message box in the keyup event but then it just looped if you hit return on the 'OK' button. If you clicked it with the mouse it went away but we try to code things so the users don't have to take their hands from the keyboard any more than possible. Thanks for your help it did point me in the right direction and saved me a lot of time. Judy
My pleasure. I see you have run into the modern developers curse, if you hold your tongue just right and face into the wind, it works. Now you can understand why I hate interacting with the textbox events. Well done.
Never underestimate the power of human stupidity RAH