Search code examples
c#textbox

Disable Text Box Selection or Clicking


Is there a way to disable a user from clicking within a text box? I've tried .ReadOnly but this disables the user from typing in the text box. I want to be able to let the user type their name maybe "Peter" but disallow clicking back so they can't type over.


Solution

  • Use the MouseUp event:

    void textBox1_MouseUp(object sender, MouseEventArgs e) {
      textBox1.SelectionStart = textBox1.Text.Length;
    }