1

I have a windows Forms application, that has a TextBox tbID

tbID.Enabled = true;
tbID.Visible = true;
tbID.Focus();
Log("tbID focused : {0}", tbID.Focused);

I want to set the TextBox to focussed. I am setting it in the above line. It doesn't seem to work. From CanFocus I found that you need to set both Enabled and Visible to true before setting Focus to true.

But even Visible is showing as false even after setting it to true

liv2hak
  • 14,472
  • 53
  • 157
  • 270
  • 3
    Does this answer your question? [how to put focus on TextBox when the form load?](https://stackoverflow.com/questions/6597196/how-to-put-focus-on-textbox-when-the-form-load) – godot Mar 15 '21 at 09:51
  • Is `TextBox.Visible = false` or `TextBox.Enabled = false` set in the designer? In this case, why? Or, can it become disabled/invisible at run-time for some reason? In any case, in what context are you try to focus it? Where / when is this code run? – Jimi Mar 15 '21 at 10:03

1 Answers1

0

Try to check tbID.InvokeRequired. If the value is true then try to make call cross-thread controls in a thread-safe way.

Make thread safe calls

Invoke required

user2250152
  • 14,658
  • 4
  • 33
  • 57