Skip to main content

Is there a way to turn off the selection of the value in a textbox field when you tab to the field?

Is there a way to turn off the selection of the value in a textbox field when you tab to the field?

You can set the SelectionStart property of the textbox to 0 in the form load event or after setting the Text property.

       method-id Form1_Load final private.
       procedure division using by value sender as object e as type System.EventArgs.
      
           set textBox1::SelectionStart to 0
           set textBox2::SelectionStart to 0
           set textBox3::SelectionStart to 0

Is there a way to turn off the selection of the value in a textbox field when you tab to the field?

Thanks


Is there a way to turn off the selection of the value in a textbox field when you tab to the field?

That did not seem to do anything.  I put it into the code when I init the form and it still selects the full field when you tab to the textbox.


Is there a way to turn off the selection of the value in a textbox field when you tab to the field?

That did not seem to do anything.  I put it into the code when I init the form and it still selects the full field when you tab to the textbox.


Is there a way to turn off the selection of the value in a textbox field when you tab to the field?

Here the other thing I found.  If you hit the end or home key and remove the selection of text, if you tab back to the field the text is not selected the next time.  Only on the initial tab to the field.


Is there a way to turn off the selection of the value in a textbox field when you tab to the field?

This is standard behavior of the textbox field. The text selection occurs when you tab into the field the first time but not if you click into the field, etc.

Try the following code:

          set textBox1::SelectionStart to 0
          set textBox2::SelectionStart to 0
          set textBox3::SelectionStart to 0
          invoke textBox1::DeselectAll
          invoke textBox2::DeselectAll
          invoke textBox3::DeselectAll

The easiest way to change the behavior of the textbox all together would be to create your own version of textbox by inheriting from it and then overriding the desired behavior.

There is a good article I found here:


Is there a way to turn off the selection of the value in a textbox field when you tab to the field?

Thanks