1、首先在各個要切換的Form內全域區塊宣告
public static bool isRunMain = false;//存取等級須為public |
2、開啟Program.cs檔,加入(自己定義的form名稱也可自行更改更好的判別方式)
if (saleForm.isRunMain) { Application.Run(new saleForm()); } else if (inputForm.isRunMain) { Application.Run(new inputForm());} else if (companyForm.isRunMain) { Application.Run(new companyForm());} |
3、在主畫面內呼叫新的畫面方法
private void button1_Click(object sender, EventArgs e) { saleForm sale = new saleForm();//新的form名稱 saleForm.isRunMain = true;//把isRunMain改為true sale.Show();//顯示新畫面 this.Hide(); //舊畫面隱藏 } |
private void Form1_FormClosing(object sender, FormClosingEventArgs e)//視窗正在關閉中 { Application.Exit();//離開 } |
private void saleForm_FormClosing(object sender, FormClosingEventArgs e) { Form1 f1 = new Form1();//叫回主畫面 f1.Show();//show } |
留言
張貼留言