Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Restricting a multiline text box

Restricting a multiline text box

Scheduled Pinned Locked Moved Visual Basic
csharphelpcssvisual-studio
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JudyV
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • J JudyV

      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

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      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

      J 2 Replies Last reply
      0
      • M Mycroft Holmes

        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

        J Offline
        J Offline
        JudyV
        wrote on last edited by
        #3

        Thanks. I was getting to that I just was wondering if perhaps there was a setting I had missed. This points me in the right direction. :) If the beatings worked I wouldn't need to do this. LOL Judy

        1 Reply Last reply
        0
        • M Mycroft Holmes

          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

          J Offline
          J Offline
          JudyV
          wrote on last edited by
          #4

          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

          J M 2 Replies Last reply
          0
          • J JudyV

            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

            J Offline
            J Offline
            JudyV
            wrote on last edited by
            #5

            Never mind. I quit displaying the message explaining that they couldn't add anymore lines and then the key supression started working. :) Thanks for all your help, Judy

            1 Reply Last reply
            0
            • J JudyV

              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

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              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

              J 1 Reply Last reply
              0
              • M Mycroft Holmes

                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

                J Offline
                J Offline
                JudyV
                wrote on last edited by
                #7

                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

                M 1 Reply Last reply
                0
                • J JudyV

                  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

                  M Offline
                  M Offline
                  Mycroft Holmes
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups