Use DialogResult in windows Form application c#

133 views Asked by At

I want to use DialogResult to go to next Form and visible or invisible any control in next form with radio button is checked. In the first form I use this code:

this.DialogResult = DialogResult.OK;
loader.Enabled = false;
this.Close();
return;

and in the next form I use this:

private void Form1_Load(object sender, EventArgs e)
{
  First_form first = new First_form();
  if (first.ShowDialog() == DialogResult.OK)
  {
     MessageBox.Show("Device Found!");
     serialPort1 = first.comport;
     first.comport.Close();
     serialPort1.Close();
     serialPort1.Open();
     timer1.Enabled = true;
     timer2.Enabled = true;
     pictureBoxConect.Visible = true;
     label_conect.Visible = true;
  }
  else
  {
     MessageBox.Show("Not Device Found!");
     pictureBoxDisconect.Visible = true;
     label_disconect.Visible = true;
  }
}

i want to use radio button in myfirst form

1

There are 1 answers

0
Zan On

Try this,

if (radioButton.Checked == true)
   this.DialogResult = DialogResult.Yes;
else
   this.DialogResult = DialogResult.Cancel;