在 WinForms 表单之间传递数据 [英] Passing data between WinForms forms
本文介绍了在 WinForms 表单之间传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的项目中创建了一个辅助表单,它可以从主表单中获取数据,并且应该在单击按钮时将一些数据传递给主表单.
这是代码:
I have made a secondary form in my project which can get data from the main form, and should pass some out to the main form when a button is clicked.
here is the code:
Add.cs:
private void button1_Click(object sender, EventArgs e)
{
main ma = new main();
ma.optionType = "add";
ma.optionName = txtName.Text;
ma.optionURL = txtURL.Text;
ma.optionInterval = "12";
//What should I pass here?
this.Close();
}
main.cs:
private string opt;// create a property
public string optionType
{
get
{
return opt;
}
set
{
opt = value;
}
}
private string opt2;// create a property
public string optionName
{
get
{
return opt2;
}
set
{
opt2 = value;
}
}
private string opt3;// create a property
public string optionURL
{
get
{
return opt3;
}
set
{
opt3 = value;
}
}
private string opt4;// create a property
public string optionInterval
{
get
{
return opt4;
}
set
{
opt4 = value;
}
}
我的问题是,在单击 button1(在 add.cs 中)后,我不知道何时尝试获取来自 add.cs 的数据.我应该用什么事件来检查数据是否来了?
My problem is that I don't know when to try to fetch the data coming from add.cs after button1 (in add.cs) was clicked. With what event should I check if the data came?
推荐答案
我只是改成这样:
添加.cs:
I just changed it to this:
add.cs:
public string optionType { get; set; }
public string optionName { get; set; }
public string optionURL { get; set; }
public string optionInterval { get; set; }
public int yCoord { get; set; }
这篇关于在 WinForms 表单之间传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文