我在嘗試從表單 1 打開表單 2 并關閉表單 1 時遇到問題,我嘗試了這些解決方案但找不到正確的解決方案:解決方案 1:-
Form2 form2 = new Form2();
form2.Show();
this.Close(); //close Form1
解決方案 2:- 在 Program.cs 檔案中
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
MyApplicationContext context = new MyApplicationContext();
Application.Run(context);
}
public class MyApplicationContext : ApplicationContext
{
private Form1 form1 = new Form1();
public MyApplicationContext()
{
form1 = new Form1();
form1.Show();
}
}
在 Form1.cs 中
Form1 form1 = new Form1();
form1.Show();
this.Close();
此解決方案有效,但關閉應用程式后,我發現它仍然在后臺運行。
我怎樣才能解決這個問題?
uj5u.com熱心網友回復:
你可以試試這段代碼:
this.Hide();
Form2 form2 = new Form2();
form2.Closed = (s, args) => this.Close();
form2.Show();
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/419995.html
標籤:
