如何在 C# 中的 winform 中传递和读取参数
How to pass and read parameters in a winform in C#
我已经阅读了一些其他问题,但我不知道如何解决我的问题。
我的申请中有两份表格。 frmMain
和 frmAdd
。我想从主窗体打开 frmAdd
,并带有要在 frmAdd
中使用的参数。下面的代码我试过
frmMain
frmAdd frm= new frmAdd("A");
frm.ShowDialog();
frmAdd
if (parameter=="A")
//Do this
else if(parameter=="B")
//Do that
我怎样才能让它发挥作用?
public partial class frmAdd : Form
{
public frmAdd() //Should I add somthing here?
{
InitializeComponent();
}
}
您可以添加参数化构造函数,以便创建带参数的表单,并使用 this() 调用无参数构造函数
public partial class frmAdd : Form
{
public frmAdd() //Should I add somthing here?
{
InitializeComponent();
}
public frmAdd(string str) : this()
{
}
}
我已经阅读了一些其他问题,但我不知道如何解决我的问题。
我的申请中有两份表格。 frmMain
和 frmAdd
。我想从主窗体打开 frmAdd
,并带有要在 frmAdd
中使用的参数。下面的代码我试过
frmMain
frmAdd frm= new frmAdd("A");
frm.ShowDialog();
frmAdd
if (parameter=="A")
//Do this
else if(parameter=="B")
//Do that
我怎样才能让它发挥作用?
public partial class frmAdd : Form
{
public frmAdd() //Should I add somthing here?
{
InitializeComponent();
}
}
您可以添加参数化构造函数,以便创建带参数的表单,并使用 this() 调用无参数构造函数
public partial class frmAdd : Form
{
public frmAdd() //Should I add somthing here?
{
InitializeComponent();
}
public frmAdd(string str) : this()
{
}
}