Form上のコントロールが表示されない場合の対処方法|C#
作成したForm
クラスを以下のように表示した際、Form
上のControl
が白くなって描画されない場合があります。
public partial class WaitDialog : Form {
public WaitDialog() {
InitializeComponent();
}
}
using (Form waitDialog = new WaitDialog()) {
waitDialog.Show();
// 重い処理
}
この問題の解決方法です。
解決方法
Application.DoEvents()
またはForm.Refresh()
をコールするとコントロールが描画されます。
Application.DoEvents() を使う
using (Form waitDialog = new WaitDialog()) {
waitDialog.Show(this);
Application.DoEvents();
// 重い処理
}
Form.Refresh() を使う
using (Form waitDialog = new WaitDialog()) {
waitDialog.Show(this);
waitDialog.Refresh();
// 重い処理
}