準備
(なし)
デザイン
- フォーム (Form1) にボタン (button1) を配置します。
- プロジェクトにフォーム (Form2) を追加します。
サンプルコード (C#)
namespace WinFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2
{
Owner = this
};
f2.Show();
}
}
}
解説
Form1 から呼び出された Form2 は常に Form1 の前面に表示されます。この場合でも Form1 の操作は可能です。フォームのモーダル表示とは違います。
結果
動作確認環境
Visual Studio 2022 Professional (.NET8 C#12)
ログ
初版:2016.05.06 Visual Studio 2015 Professional (C# 6.0)
