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. C#
  4. TextBox Focus

TextBox Focus

Scheduled Pinned Locked Moved C#
csharpquestion
7 Posts 5 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.
  • B Offline
    B Offline
    bhanu12345
    wrote on last edited by
    #1

    In My Application I have Three textboxes for phone number to maintain the format as 3-3-4.Once the user enters the first 3 numbers of a phone number the focus should automatically go to nextbox How can I do it in C# chanti

    R M Q 3 Replies Last reply
    0
    • B bhanu12345

      In My Application I have Three textboxes for phone number to maintain the format as 3-3-4.Once the user enters the first 3 numbers of a phone number the focus should automatically go to nextbox How can I do it in C# chanti

      R Offline
      R Offline
      rah_sin
      wrote on last edited by
      #2

      on the textbox1 keyup event u can check the length of text entered in textbox by following way textbox1.text.length and then check the condition if(textbox1.text.length==3) textbox2.focus(); same way you can put same condition for textbox2 on its keyup event to transfer focus on textbox3.

      rahul

      1 Reply Last reply
      0
      • B bhanu12345

        In My Application I have Three textboxes for phone number to maintain the format as 3-3-4.Once the user enters the first 3 numbers of a phone number the focus should automatically go to nextbox How can I do it in C# chanti

        M Offline
        M Offline
        mikone
        wrote on last edited by
        #3

        Hi, you could do this by binding the textboxes KeyUp-Event. The first argument passed to the eventhandler is the triggering object (in this case the textbox where the user has written in). the code for the eventhandler could look like: TextBox mytxtbox = (TextBox) sender; if (mytxtbox.Text.Length == 3) theNextTextBox.Focus(); if you need further assistance feel free to ask :)

        1 Reply Last reply
        0
        • B bhanu12345

          In My Application I have Three textboxes for phone number to maintain the format as 3-3-4.Once the user enters the first 3 numbers of a phone number the focus should automatically go to nextbox How can I do it in C# chanti

          Q Offline
          Q Offline
          quiteSmart
          wrote on last edited by
          #4

          hi Chanti, You can do this by more than one way. The most easy way that I could think of right now is to set the maximum lenght property of the three text boxes (lets say firstTextBox, secondTextBox, thirdTextBox) to 3-3-4 simultanuously. After doing so the program want allow u to type more than 3 digits in the first text box but wont take u to the next one. So u have to fire an event of that text box. The event that u should fire is the TextChanged event and write inside this method the following code: if (firstTextBox.Text.Length == 3) { secondTextBox.Focus(); } This will take the focus and the next character to the secondTextBox. And u can do this for the other textboxes too. If you need any help in any other issue, don't be shy to add me at the following MSN address: jamilaboukhalil@hotmail.com or you can just send a mail. Jamil Abou khalil

          A 1 Reply Last reply
          0
          • Q quiteSmart

            hi Chanti, You can do this by more than one way. The most easy way that I could think of right now is to set the maximum lenght property of the three text boxes (lets say firstTextBox, secondTextBox, thirdTextBox) to 3-3-4 simultanuously. After doing so the program want allow u to type more than 3 digits in the first text box but wont take u to the next one. So u have to fire an event of that text box. The event that u should fire is the TextChanged event and write inside this method the following code: if (firstTextBox.Text.Length == 3) { secondTextBox.Focus(); } This will take the focus and the next character to the secondTextBox. And u can do this for the other textboxes too. If you need any help in any other issue, don't be shy to add me at the following MSN address: jamilaboukhalil@hotmail.com or you can just send a mail. Jamil Abou khalil

            A Offline
            A Offline
            Amar Chaudhary
            wrote on last edited by
            #5

            yes this is right solution the previous one does fail when we keep the key pressed :):)

            M Q 2 Replies Last reply
            0
            • A Amar Chaudhary

              yes this is right solution the previous one does fail when we keep the key pressed :):)

              M Offline
              M Offline
              mikone
              wrote on last edited by
              #6

              then you should use the keypressed value ;) if there already are 3 characters in the textbox set e.Handled to true and set focus to the next textbox otherwise allow it to write the value :)

              1 Reply Last reply
              0
              • A Amar Chaudhary

                yes this is right solution the previous one does fail when we keep the key pressed :):)

                Q Offline
                Q Offline
                quiteSmart
                wrote on last edited by
                #7

                Yea right, that's the negative side about the keydown/keyup/keypressed events.u don't know which key is pressed. Anyway hope that i did benifit u. Feel free to contact me at my MSN address jamilaboukhalil@hotmail.com. Take care

                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