C#跨窗體操作(引用傳遞) 實例代碼
更新時間:2013年03月25日 14:24:29 作者:
現(xiàn)在給大家介紹一種最簡單的跨窗體操作,WinForm的窗體是一個類,C#的類是引用類型,那么我們應(yīng)該可以將WinForm窗體類進行傳遞,那不就可以進行操作了么?
效果描述:
有三個窗體然后順序分別是
(1)點擊第一個窗體中的按鈕彈出第二個窗體,隱藏第一個窗體
(2)第二個窗體到一定時間彈出第三個窗體
(3)點擊第三個窗體的按鈕關(guān)閉第三個和第二個窗體,彈出第一個窗體
From1
復(fù)制代碼 代碼如下:
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void 打開form2隱藏form1_Click(object sender, EventArgs e)
{
Form2 f = new Form2();
f.fatherForm = this;
f.Show();
this.Hide();
}
}
}
Form2
復(fù)制代碼 代碼如下:
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public Form1 fatherForm;
private void 打開from3_Click(object sender, EventArgs e)
{
Form3 f = new Form3();
f.fatherForm = this;
f.Show();
}
}
}
Form3
復(fù)制代碼 代碼如下:
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();
}
}
}
相關(guān)文章
c#橋接模式(bridge結(jié)構(gòu)模式)用法實例
這篇文章主要介紹了c#橋接模式(bridge結(jié)構(gòu)模式)用法,較為詳細(xì)的分析了橋接模式的原理與用法實例,具有一定的參考借鑒價值,需要的朋友可以參考下2014-12-12讀寫XML文件的內(nèi)容并將其顯示在ListView控件上的方法
下面小編就為大家?guī)硪黄x寫XML文件的內(nèi)容并將其顯示在ListView控件上的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02C#winform中數(shù)據(jù)庫綁定DataGrid的實現(xiàn)
本文主要介紹了C#winform中數(shù)據(jù)庫綁定DataGrid的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05