将Form1的窗口设计属性抓取为2

时间:2016-05-04 04:56:02

标签: c# winforms inheritance

我试图Form1 Windows设计专有对象转换为Form 2 。所以基本上我想做的是使用两个单选按钮并将它们放在表单2中的if语句中。像这样的例子

表格1(当前代码)

if (radioBtnOne.Checked == true)
{
  Form2 mm = new Form2();
  this.Hide();
  mm.Show();
}

表格2(我想要的)

if (radioBtnOne.checked == true)
{
   -Action goes here-
}

表单1中的代码是一个按钮方法,因此它确保在切换到下一个表单之前检查单选按钮但是因为我检查了单选按钮我还想在load方法中的表单2中使用它。

1 个答案:

答案 0 :(得分:0)

如果您需要从form2访问form1中的任何内容,则需要通过form2的构造函数或Property传递该内容。 (构造函数注入和属性注入)

在表单2中,添加

public RadioButton radioBtnOne { set; get;}

然后

if (radioBtnOne.Checked == true)
{
  Form2 mm = new Form2();
  mm.radioBtnOne = this.radioBtnOne;
  this.Hide();
  mm.Show();
}