TextBox Trim question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Woody Splawn

    TextBox Trim question

    It is hard for me to imagine a time when you would not want to have the data
    in a textbox control trimmed. I am hoping there is some sort of switch that
    can be set for all text boxes so that when the user leaves the text box it
    gets trimmed. Is there such a thing. If not, does this mean I need to
    write some sort of trimming code for each text box I place on a Winform. If
    so, what is the simplest and easiest way for me to see to it that all text
    boxes get trimmed?



  • William Ryan

    #2
    Re: TextBox Trim question

    AFAIK, there's not a built in method for this but you could easily derive a
    control and when text is 'set', make sure you trim it in there.
    "Woody Splawn" <woody@splawns. com> wrote in message
    news:OYCWWvV1DH A.3656@TK2MSFTN GP11.phx.gbl...[color=blue]
    > It is hard for me to imagine a time when you would not want to have the[/color]
    data[color=blue]
    > in a textbox control trimmed. I am hoping there is some sort of switch[/color]
    that[color=blue]
    > can be set for all text boxes so that when the user leaves the text box it
    > gets trimmed. Is there such a thing. If not, does this mean I need to
    > write some sort of trimming code for each text box I place on a Winform.[/color]
    If[color=blue]
    > so, what is the simplest and easiest way for me to see to it that all text
    > boxes get trimmed?
    >
    >
    >[/color]


    Comment

    • Cor

      #3
      Re: TextBox Trim question

      Hi Woody,

      Two days ago someone did ask something, that did look strange in all the
      answer that have been given here, but when we did something (not one person
      but more persons) in this newsgroup it did work and it is quiet normal that
      it does work.

      I thought with that I can do in future something.
      Now you are asking for something I thought that I could, so I did make it.

      Try it, I thought that it does what you ask

      I hope this was what you where looking for?

      Cor

      \\\
      Private Sub Form1_Load(ByVa l sender As Object, _
      ByVal e As System.EventArg s) Handles MyBase.Load
      Dim txtboxarea As TextBox() = New TextBox() {TextBox1, TextBox2}
      'In the array are all the textboxes you want to trim that you made in design
      time
      For Each txt As TextBox In txtboxarea
      AddHandler txt.LostFocus, AddressOf TextBox_LostFoc us
      Next
      End Sub
      Private Sub TextBox_LostFoc us(ByVal sender As Object, _
      ByVal e As System.EventArg s)
      DirectCast(send er, TextBox).Text = _
      Trim(DirectCast (sender, TextBox).Text)
      End Sub
      ///









      [color=blue]
      > It is hard for me to imagine a time when you would not want to have the[/color]
      data[color=blue]
      > in a textbox control trimmed. I am hoping there is some sort of switch[/color]
      that[color=blue]
      > can be set for all text boxes so that when the user leaves the text box it
      > gets trimmed. Is there such a thing. If not, does this mean I need to
      > write some sort of trimming code for each text box I place on a Winform.[/color]
      If[color=blue]
      > so, what is the simplest and easiest way for me to see to it that all text
      > boxes get trimmed?
      >
      >
      >[/color]


      Comment

      • Armin Zingler

        #4
        Re: TextBox Trim question

        "Woody Splawn" <woody@splawns. com> schrieb[color=blue]
        > It is hard for me to imagine a time when you would not want to have
        > the data in a textbox control trimmed. I am hoping there is some
        > sort of switch that can be set for all text boxes so that when the
        > user leaves the text box it gets trimmed. Is there such a thing. If
        > not, does this mean I need to write some sort of trimming code for
        > each text box I place on a Winform. If so, what is the simplest and
        > easiest way for me to see to it that all text boxes get trimmed?[/color]

        solution 1: write a derived Textbox that trims in the leave event.
        solution 2: handle the leave event in the same event handler for all
        textboxes.


        --
        Armin




        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: TextBox Trim question

          * "Woody Splawn" <woody@splawns. com> scripsit:[color=blue]
          > It is hard for me to imagine a time when you would not want to have the data
          > in a textbox control trimmed. I am hoping there is some sort of switch that
          > can be set for all text boxes so that when the user leaves the text box it
          > gets trimmed. Is there such a thing. If not, does this mean I need to
          > write some sort of trimming code for each text box I place on a Winform. If
          > so, what is the simplest and easiest way for me to see to it that all text
          > boxes get trimmed?[/color]

          You can create an inherited control (inheriting from
          'System.Windows .Forms.TextBox' which handles its 'Validating' event and
          trims its contents there. Then you will have to use the new textbox
          instead of the standard Windows Forms textbox.

          --
          Herfried K. Wagner [MVP]
          <http://www.mvps.org/dotnet>

          Comment

          • Cor

            #6
            OT: Re: TextBox Trim question

            Hi Herfried,

            Did you look at my solution I think it is wonderful?

            Cor
            [color=blue]
            > You can create an inherited control (inheriting from
            > 'System.Windows .Forms.TextBox' which handles its 'Validating' event and
            > trims its contents there. Then you will have to use the new textbox
            > instead of the standard Windows Forms textbox.[/color]


            Comment

            • Peter Huang

              #7
              RE: TextBox Trim question

              HI Woody,

              Did you have any concern on this issue?
              If so please post in the newsgroup.

              Regards,
              Peter Huang
              Microsoft Online Partner Support
              Get Secure! www.microsoft.com/security
              This posting is provided "as is" with no warranties and confers no rights.

              Comment

              • Peter Huang

                #8
                RE: TextBox Trim question

                HI Woody,

                Did you have any concern on this issue?
                If so please post in the newsgroup.

                Regards,
                Peter Huang
                Microsoft Online Partner Support
                Get Secure! www.microsoft.com/security
                This posting is provided "as is" with no warranties and confers no rights.

                Comment

                Working...