public string _FNAME = string.Empty; //global variable
public Form2(string FNAME) //parameter
{
InitializeComponent();
_rdbtnSpecial.Hide();
_rdbtnSharing.Hide();
_FNAME = FNAME; // for data calling
我使用了该代码,以便我可以从表单1到表单2获取数据。我很难从表格3回到表格2
Form2 _form2 = new Form2()
this.Show();
我应该向该代码添加什么,以便从表单3返回到表单2? 谢谢你:))
答案 0 :(得分:0)
我想我发现了你的问题。这是一个简单的错字。
替换
Form2 _form2 = new Form2();
this.Show();
使用
Form2 _form2 = new Form2();
_form2.Show();
如果你想恢复FNAME,请在下方发表评论,我也会解释。
答案 1 :(得分:0)
我的建议是使用ShowDialog
功能。您可以像这样使用它:
窗体2:
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
using (var loadingScreen = new Form3())
{
var formResult = loadingScreen.ShowDialog();
if (formResult == DialogResult.Cancel)
{
// form3 failed
}
else if (dr == DialogResult.OK)
{
// form3 completed
}
loadingScreen.Close();
}
}
}
现在在Form3中,您可以创建一个返回所需内容的方法:
pubilc partial class Form3 : Form
{
//.. other code
public string loadMethod()
{
this.DialogResult = DialogResult.OK; // DialogResult.Cancel if failed
}
}