我有两个表单,Form1和Form2.我希望Form2在我调试程序时加载,然后在btnclickevent(在Form2中)关闭Form2并加载Form1并将文本框中的输入值导入Form1中的代码.
如果有些事情需要谨慎,请告诉我.
private void Form1_Load(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
}
Run Code Online (Sandbox Code Playgroud)
首先显示的表单由Program.cs中的Main()方法确定.例如,你可以看起来像这样:
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form main;
if (System.Diagnostics.Debugger.IsAttached) main = new Form2();
else main = new Form1();
Application.Run(main);
}
Run Code Online (Sandbox Code Playgroud)
哪个仍然很难在Form2之后显示Form1,你可以这样解决它:
if (System.Diagnostics.Debugger.IsAttached) {
using (var debug = new Form2()) {
if (debug.ShowDialog() != DialogResult.OK) return;
}
}
Application.Run(new Form1());
Run Code Online (Sandbox Code Playgroud)