Assuming this is:
1. WinForms
2. Form1 is the main Form which created, and made visible, the
'f2 Form
3. the Button and RadioButton are on Form1
private void button_Click (object sender, EventArgs e)
{
if (radio1.Checked)
{
if(f2 != null) f2.Close();
}
}
Should you be using a CheckBox here ? Why do you even need a Button ? The idea you check something to dispose it seems odd.
Consider if you should hide, rather than close, 'f2.
... edit ... CheckBox example
Form2 f2 = new Form2();
const string CbxShowTxt = "Show Second Form";
const string CbxHideTxt = "Hide Second Form";
private void Form1_Load(object sender, EventArgs e)
{
checkBox1.Text = CbxShowTxt;
checkBox1.Checked = false;
}
private void checkBox1_CheckStateChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
f2.Show();
checkBox1.Text = CbxHideTxt;
}
else
{
f2.Hide();
checkBox1.Text = CbxShowTxt;
}
}
... end edit ...