現(xiàn)在給大家介紹一種最簡(jiǎn)單的跨窗體操作
WinForm的窗體是一個(gè)類(lèi),C#的類(lèi)是引用類(lèi)型,那么我們應(yīng)該可以將WinForm窗體類(lèi)進(jìn)行傳遞,那不就可以進(jìn)行操作了么?
效果描述: 有三個(gè)窗體然后順序分別是 (1)點(diǎn)擊第一個(gè)窗體中的按鈕彈出第二個(gè)窗體,隱藏第一個(gè)窗體 (2)第二個(gè)窗體到一定時(shí)間彈出第三個(gè)窗體 (3)點(diǎn)擊第三個(gè)窗體的按鈕關(guān)閉第三個(gè)和第二個(gè)窗體,彈出第一個(gè)窗體 |
From1
- using System;
- using System.Windows.Forms;
-
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
-
- private void 打開(kāi)form2隱藏form1_Click(object sender, EventArgs e)
- {
- Form2 f = new Form2();
- f.fatherForm = this;
- f.Show();
- this.Hide();
- }
- }
- }
Form2
- using System;
- using System.Windows.Forms;
-
- namespace WindowsFormsApplication1
- {
- public partial class Form2 : Form
- {
- public Form2()
- {
- InitializeComponent();
- }
-
- public Form1 fatherForm;
-
- private void 打開(kāi)from3_Click(object sender, EventArgs e)
- {
- Form3 f = new Form3();
- f.fatherForm = this;
- f.Show();
- }
- }
- }
Form3
- using System;
- using System.Windows.Forms;
-
- namespace WindowsFormsApplication1
- {
- public partial class Form3 : Form
- {
- public Form3()
- {
- InitializeComponent();
- }
-
- public Form2 fatherForm;
-
- private void 關(guān)閉form3from2顯示from1_Click(object sender, EventArgs e)
- {
- fatherForm.fatherForm.Show();
- fatherForm.Close();
- this.Close();
- }
-
- }
- }