How to disable selection in TextBox

I want to turn off the text selection and click on the middle of the text in the TextBox, but the user should be able to enter this TextBox and write at the end of the earlier text, so I cannot make it ReadOnlyor Enable = false.

I am trying to process MouseDownand do the following:

input.Select(input.Text.Length, 0);

This helps with placing the cursor in the middle of the text, but the user can still make a selection from the end.

I also do the MessageBox()on event MouseDown, but in this case the user cannot click on the textBox and write anything.

The last attempt was to set focus()in another control and focus, after some time, but that did not work. The user can still make a choice.

How can i do this?

+5
source share
3 answers

If it matches the user interface / user model, another approach is to use two text fields: read-only with the previous text, which the user can see and act (if that’s what he needs to do) and editable for new text along with the button, to commit new text to a read-only text box (and save layer).

, , "", , Backspace &mdash, , , .

+2

Click

: DoubleClick MouseLeave, . .

    private void textBox1_Click(object sender, EventArgs e)
    {
        ((TextBox) sender).SelectionLength = 0;
    }
+5

MouseDown, , , MouseUp, , .

SelectionChanged.

:

input.Select(input.Text.Length, 0);

.

+1

All Articles