LoginSignup
3
1

More than 5 years have passed since last update.

フォーム上のロード時にControlにフォーカスを設定する方法

Last updated at Posted at 2016-08-08

Windowsアプリケーションで、フォーム上のコントロールにフォーカスを設定する場合のお話。

フォームをロードする時に、コントロールにフォーカスを設定しようと思いコードを記述。

テキストボックスにフォーカスを当てたかったので、こう書いた。
this.TextBox.Focus();

当たらない…(・・;)

調べてみると、これではダメなコードらしい。

正しくは、フォームのActiveControlプロパティにコントロールを設定する。
this.ActiveControl = this.TextBox;

当たった!(´ω`*)

コントロールのFocus()に惑わされてしまった。

3
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1