【问题标题】:Use DialogResult in windows Form application c#在windows Form应用程序c#中使用DialogResult
【发布时间】:2018-02-19 07:11:07
【问题描述】:

我想使用 DialogResult 转到下一个表单,并且选中下一个表单中带有单选按钮的任何控件可见或不可见。 在第一种形式中,我使用以下代码:

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

在下一个表格中我使用这个:

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;
  }
}

我想在我的第一个表单中使用单选按钮

【问题讨论】:

  • 问题不清楚。
  • 您可以通过在两种表单中声明一些公共属性并在同一个命名空间中访问它们来做到这一点。或者你可以通过将参数传递给构造函数来做到这一点。

标签: c# radio-button dialogresult


【解决方案1】:

试试这个,

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-16
    • 1970-01-01
    • 2019-03-22
    • 2012-05-17
    • 2014-04-19
    • 1970-01-01
    • 2011-01-29
    • 2018-11-04
    相关资源
    最近更新 更多