--- lang: ja-jp breaks: true --- # WinForm WPFで作成されたのダイアログ(Window)を モーダルウインドウとして表示する 2022-03-29 ```csharp= ProgressDialog progressDialog = new(); progressDialog.WindowStartupLocation = WindowStartupLocation.CenterOwner; //progressDialog.Owner = this; WindowInteropHelper helper = new WindowInteropHelper(progressDialog); helper.Owner = this.Handle; progressDialog.ShowInTaskbar = false; //progressDialog.Left = this.Left + (this.Width / 2) - (progressDialog.Width / 2); //progressDialog.Top = this.Top + (this.Height / 2) - (progressDialog.Height / 2); progressDialog.ShowDialog(); ``` :::info this:WinForm ProgressDialog:WPF ::: :::info ポイントは以下の通り * `WindowInteropHelper`を使うこと * `WindowStartupLocation`を設定した後に`Owner = this`を行うこと。 * `helper.Owner` には、Windowsのハンドルを指定する必要がある。Controlのハンドルでは正常に動作しない。 ::: ###### tags: `WinForm` `WPF` `ShowDialog` `モーダルウインドウ`