Formatting TextBox ?

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

    Formatting TextBox ?

    Hell
    I have a few text boxes on my form and I need in one to allow only numbers and on the other only letters how to enforce that you can't enter numbers in a letters textbox and...
    Jack
  • One Handed Man \( OHM#\)

    #2
    Re: Formatting TextBox ?

    Private Sub TextBox1_KeyPre ss(ByVal sender As Object, ByVal e As
    System.Windows. Forms.KeyPressE ventArgs) Handles TextBox1.KeyPre ss

    If Char.IsLetter(e .KeyChar) Then

    'OK

    Else

    'Not OK

    e.Handled = True

    End If

    End Sub

    OHM





    "Jack" <anonymous@disc ussions.microso ft.com> wrote in message
    news:3E166B3C-FC65-4F99-9711-8F105769A4D9@mi crosoft.com...[color=blue]
    > Hello
    > I have a few text boxes on my form and I need in one to allow only numbers[/color]
    and on the other only letters how to enforce that you can't enter numbers in
    a letters textbox and...[color=blue]
    > Jack[/color]


    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Formatting TextBox ?

      * "=?Utf-8?B?SmFjaw==?=" <anonymous@disc ussions.microso ft.com> scripsit:[color=blue]
      > I have a few text boxes on my form and I need in one to allow only
      > numbers and on the other only letters how to enforce that you can't
      > enter numbers in a letters textbox and...[/color]

      Instead of resticting the type of input, I would add code to the
      control's 'Validating' event and set an ErrorProvider to make the user
      aware of the invalid input. That's more user-friendly because you do
      not forbid the user to do editing pasted text from the clipboard
      etc. inside the textboxes.

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

      Comment

      • One Handed Man \( OHM#\)

        #4
        Re: Formatting TextBox ?


        granted!



        "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
        news:Oh8RLZVJEH A.3596@tk2msftn gp13.phx.gbl...[color=blue]
        > * "=?Utf-8?B?SmFjaw==?=" <anonymous@disc ussions.microso ft.com> scripsit:[color=green]
        > > I have a few text boxes on my form and I need in one to allow only
        > > numbers and on the other only letters how to enforce that you can't
        > > enter numbers in a letters textbox and...[/color]
        >
        > Instead of resticting the type of input, I would add code to the
        > control's 'Validating' event and set an ErrorProvider to make the user
        > aware of the invalid input. That's more user-friendly because you do
        > not forbid the user to do editing pasted text from the clipboard
        > etc. inside the textboxes.
        >
        > --
        > Herfried K. Wagner [MVP]
        > <URL:http://dotnet.mvps.org/>[/color]


        Comment

        • Cor Ligthert

          #5
          Re: Formatting TextBox ?

          Hi Jack,

          I would take that nice piece of code from OHM and that what Herfried stated.

          I think it is nicer that a user gets direct a signal when he is typing and
          not after he had done a lot.

          If you take the validate than, you prevent than all other things in one
          time.

          Just my thought

          Cor


          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: Formatting TextBox ?

            * "One Handed Man \( OHM#\)" <news.microsoft .com> scripsit:[color=blue]
            > granted![/color]

            LOL!

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

            Comment

            Working...