https://youtu.be/vaWk6yxQWX0
// FormShowDialog.cs
public partial class FormShowDialog : Form
{
int OpenCount = 0;
public FormShowDialog()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if(DuoCheck("SettingForm")) return;
//SettingForm dlg = new SettingForm(10, 20);
SettingForm dlg = new SettingForm();
dlg.exNum1 = 111;
dlg.exNum2 = 222;
// dlg.Show(this);
//dlg.StartPosition = FormStartPosition.CenterScreen;
//dlg.StartPosition = FormStartPosition.CenterParent;
dlg.FormClosing += SettingCloseEvent;
//dlg.TopMost = true;
dlg.Text = "Setting Option";
dlg.Show();
OpenCount++;
label1.Text = "Count : " + OpenCount;
//dlg.ShowDialog();
//this.Enabled = false;
}
private void SettingCloseEvent(object sender, EventArgs e)
{
//this.Enabled = true;
OpenCount--;
label1.Text = "Count : " + OpenCount;
}
private bool DuoCheck(string name)
{
foreach(Form frm in Application.OpenForms)
{
if(frm.Name != name) continue;
if(frm.WindowState == FormWindowState.Minimized)
frm.WindowState = FormWindowState.Normal;
frm.Activate();
return true;
}
return false;
}
}
// SettingForm.cs
public partial class SettingForm : Form
{
public int exNum1, exNum2 ;
public SettingForm()
{
InitializeComponent();
}
public SettingForm(int num1, int num2)
{
InitializeComponent();
label1.Text = "" + num1;
label2.Text = "" + num2;
label3.Text = "" + (num1 + num2);
}
private void SettingForm_Load(object sender, EventArgs e)
{
label1.Text = "" + exNum1;
label2.Text = "" + exNum2;
label3.Text = "" + (exNum1 + exNum2);
}
}