Mobius
Mobius

Reputation: 699

Is there an equivalent to java's setFocusable() in C#?

I have a RichTextBox that is focusable when the program begins. After the user types in a certain number of characters, I want to stop them from changing/adding/etc anything else to the text box.

Originally I wrote this as a Java app and used userInputBox.setFocusable(false), but I cannot find an equivalent way to programatically change this in C#. I am building a Windows Forms application. I don't have any other container or object that I want the user to interact with so I cannot use whatever.Focus() to pull it away from my text box. Thanks.

Upvotes: 0

Views: 280

Answers (2)

Kendall Frey
Kendall Frey

Reputation: 44374

Setting ReadOnly = true or Enabled = false should do the trick, unless you really need the control to be unfocusable, in which case Oded has a good answer.

Upvotes: 1

Oded
Oded

Reputation: 499312

C# has an event model that is extensively used in winforms.

You can handle the GotFocus event of the control to unfocus it by calling Focus() on a different control.

Upvotes: 2

Related Questions