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. another textbox question

another textbox question

Scheduled Pinned Locked Moved C#
question
9 Posts 3 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.
  • M Offline
    M Offline
    melanieab
    wrote on last edited by
    #1

    Hi again, I have a textbox where the text is longer than the textbox width. When I type text in and leave, the beginning of the string shows, and focus goes on to the next box. But if I don't change the text (just tab through or whatever), the beginning of the string is cut off, leaving the end of the string visible. I do use textbox.SelectionStart = 0;, but it it only works if text is changed. Any suggestions??? Thanks again, Mel

    D 1 Reply Last reply
    0
    • M melanieab

      Hi again, I have a textbox where the text is longer than the textbox width. When I type text in and leave, the beginning of the string shows, and focus goes on to the next box. But if I don't change the text (just tab through or whatever), the beginning of the string is cut off, leaving the end of the string visible. I do use textbox.SelectionStart = 0;, but it it only works if text is changed. Any suggestions??? Thanks again, Mel

      D Offline
      D Offline
      Daniel Monzert
      wrote on last edited by
      #2

      Hm.. Maybe try to add [code]textbox.SelectionStart = 0;[/code] to the LostFocus event?

      M 1 Reply Last reply
      0
      • D Daniel Monzert

        Hm.. Maybe try to add [code]textbox.SelectionStart = 0;[/code] to the LostFocus event?

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

        That's the weird part, I have the FocusLeave event. private void txtBoxLeave(object sender, System.EventArgs e) { textbox.SelectionStart = 0; ... } Again, it works when the text is altered (even if it ends up being the exact same text), but not if nothing at all is done. :confused: Mel

        M 1 Reply Last reply
        0
        • M melanieab

          That's the weird part, I have the FocusLeave event. private void txtBoxLeave(object sender, System.EventArgs e) { textbox.SelectionStart = 0; ... } Again, it works when the text is altered (even if it ends up being the exact same text), but not if nothing at all is done. :confused: Mel

          M Offline
          M Offline
          Marc 0
          wrote on last edited by
          #4

          Maybe you can cheat a little bit?:

          private void txtBoxLeave(object sender, System.EventArgs e) {
          if (textbox.Text.Length > 0) {
          textbox.SelectionStart = 1;
          }
          textbox.SelectionStart = 0;
          }

          Dunno if this works though... Pompiedompiedom... ;)


          "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick

          M 1 Reply Last reply
          0
          • M Marc 0

            Maybe you can cheat a little bit?:

            private void txtBoxLeave(object sender, System.EventArgs e) {
            if (textbox.Text.Length > 0) {
            textbox.SelectionStart = 1;
            }
            textbox.SelectionStart = 0;
            }

            Dunno if this works though... Pompiedompiedom... ;)


            "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick

            M Offline
            M Offline
            melanieab
            wrote on last edited by
            #5

            It just refuses to work. I even put a messagebox in before selectionstart = 1, and the messagebox showed up ok. But no beginning of the string. (If it helps anyone get any more ideas, pressing only the left arrow before leaving the textbox is enough to get the beginning part. And I did try adding a SendKeys.Send("{Left}") to the KeyDown event, but that only sent a left to the next textbox (even though it was before the command to focus on the next textbox), which I'm not sure I understand.) :wtf: Mel

            M M 2 Replies Last reply
            0
            • M melanieab

              It just refuses to work. I even put a messagebox in before selectionstart = 1, and the messagebox showed up ok. But no beginning of the string. (If it helps anyone get any more ideas, pressing only the left arrow before leaving the textbox is enough to get the beginning part. And I did try adding a SendKeys.Send("{Left}") to the KeyDown event, but that only sent a left to the next textbox (even though it was before the command to focus on the next textbox), which I'm not sure I understand.) :wtf: Mel

              M Offline
              M Offline
              Marc 0
              wrote on last edited by
              #6

              Ok, let me try again:

              private void txtBoxLeave(object sender, System.EventArgs e) {
              // You say that it only works if thge text is altered, so lets alter the text :P
              // Again, i don't know if this works...
              textbox.Text = textbox.Text + " "
              textbox.Text = textbox.Text.SubString(0, textbox.Text.Length - 1)

              textbox.SelectionStart = 0;
              

              }

              Pompiedompiedom... ;)


              "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick

              M 1 Reply Last reply
              0
              • M melanieab

                It just refuses to work. I even put a messagebox in before selectionstart = 1, and the messagebox showed up ok. But no beginning of the string. (If it helps anyone get any more ideas, pressing only the left arrow before leaving the textbox is enough to get the beginning part. And I did try adding a SendKeys.Send("{Left}") to the KeyDown event, but that only sent a left to the next textbox (even though it was before the command to focus on the next textbox), which I'm not sure I understand.) :wtf: Mel

                M Offline
                M Offline
                melanieab
                wrote on last edited by
                #7

                Ok, got it going. :-D It's as simple as textbox.Select(0,0);

                1 Reply Last reply
                0
                • M Marc 0

                  Ok, let me try again:

                  private void txtBoxLeave(object sender, System.EventArgs e) {
                  // You say that it only works if thge text is altered, so lets alter the text :P
                  // Again, i don't know if this works...
                  textbox.Text = textbox.Text + " "
                  textbox.Text = textbox.Text.SubString(0, textbox.Text.Length - 1)

                  textbox.SelectionStart = 0;
                  

                  }

                  Pompiedompiedom... ;)


                  "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick

                  M Offline
                  M Offline
                  melanieab
                  wrote on last edited by
                  #8

                  Hey, Thanks a lot for looking again. I did try adding stuff to the text, but it was still refusing to work for me. I just posted what I found to do the trick before seeing your message. Anyway, thanks again, and happy holidays! Mel

                  M 1 Reply Last reply
                  0
                  • M melanieab

                    Hey, Thanks a lot for looking again. I did try adding stuff to the text, but it was still refusing to work for me. I just posted what I found to do the trick before seeing your message. Anyway, thanks again, and happy holidays! Mel

                    M Offline
                    M Offline
                    Marc 0
                    wrote on last edited by
                    #9

                    I'm happy you got it working. You have happy holidays too! :D Pompiedompiedom... ;)


                    "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick

                    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