0

I want to disable a textbox after user has inserted a value. I have tried playing with the "KeyPress" property but the first digit I type in is also the "KeyPress", so it locks on the first character. Maybe I can get the textbox to lock after pressing Enter or using Tab. What will be the best way to do this?

3
  • 2
    Try to handle TextChanged event instead. Commented Dec 14, 2012 at 6:40
  • 1
    'TextChanged' event also locks on the first character Commented Dec 14, 2012 at 6:42
  • what should happen when the user leaves the textbox but with out typing any value? Commented Dec 14, 2012 at 6:48

4 Answers 4

4

It sounds like you want to disable the box after the person leave it. (I assume that from your Enter/Tab option.) If so, look into the TextBox.LostFocus event.

Sign up to request clarification or add additional context in comments.

Comments

1

Though, the "Best" generally depends on the customer requirement, I would do the disabling act on the Lost Focus event.

 private void textBox2_Leave(object sender, EventArgs e)
  {
       textBox2.Enabled = false;
  }

Thanks

Comments

0

Just use Leave event and in body assign Enabled to false;

Comments

0

you can use the LostFocus event or the ManipulationCompleted event handler

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.