c#winform窗口頁(yè)面一打開就加載的實(shí)現(xiàn)方式
更新時(shí)間:2023年06月16日 10:52:42 作者:zzn的進(jìn)階筆記
這篇文章主要介紹了c#winform窗口頁(yè)面一打開就加載的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
c#winform窗口頁(yè)面一打開就加載
//頁(yè)面一打開就加載這個(gè)方法 this.Load += new EventHandler(SQLGetTime_Load);
文本框設(shè)置默認(rèn)值,一打開就顯示
private String text1 = "主賬薄"; private String text2 = "機(jī)器設(shè)備"; private String text3 = "JQSB0000001"; private String text4 = "打印機(jī)JQSB000001"; private String text5 = "臺(tái)"; private String text6 = "數(shù)量"; private String text7 = "2002-02-02"; private String text8 = ""; private String text9 = "經(jīng)營(yíng)用"; private String text10 = "正常使用"; private String text11 = "購(gòu)入"; private String text12 = ""; private String text13 = ""; private String text14 = ""; public void SetAttribute() { textBox1.Text = text1;//設(shè)置默認(rèn)值 textBox2.Text = text2;//設(shè)置默認(rèn)值 textBox3.Text = text3;//設(shè)置默認(rèn)值 textBox4.Text = text4;//設(shè)置默認(rèn)值 textBox4.Text = text4;//設(shè)置默認(rèn)值 textBox5.Text = text5;//設(shè)置默認(rèn)值 textBox6.Text = text6;//設(shè)置默認(rèn)值 dateTimePicker1.Text = text7;//設(shè)置默認(rèn)值 textBox8.Text = text8;//設(shè)置默認(rèn)值 textBox9.Text = text9;//設(shè)置默認(rèn)值 textBox10.Text = text10;//設(shè)置默認(rèn)值 textBox11.Text = text11;//設(shè)置默認(rèn)值 textBox12.Text = text12;//設(shè)置默認(rèn)值 textBox13.Text = text13;//設(shè)置默認(rèn)值 textBox14.Text = text14;//設(shè)置默認(rèn)值 //MessageBox.Show("成功"); } private void SQLGetTime_Load(object sender, EventArgs e) { SetAttribute();//窗體一加載就設(shè)置文本框的默認(rèn)狀態(tài), }
c#winform加載界面
先上效果圖
代碼結(jié)構(gòu)包含三個(gè)部分(調(diào)用方-主線程,被調(diào)用方-加載顯示的界面,一個(gè)靜態(tài)類)
調(diào)用的方的界面
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } int i = 0; /// <summary> /// 開啟窗口 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { ++i; ThreadNewFrm.Show(i.ToString(), i); } /// <summary> /// 關(guān)閉窗口 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { ThreadNewFrm.Close(); } } }
被調(diào)用方的界面(界面中有一個(gè)定時(shí)器 System.Windows.Forms.Timer類型)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } int i = 0; /// <summary> /// 開啟窗口 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { ++i; ThreadNewFrm.Show(i.ToString(), i); } /// <summary> /// 關(guān)閉窗口 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { ThreadNewFrm.Close(); } } }
靜態(tài)類
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp1 { public partial class Form2 : Form { public Form2() { InitializeComponent(); } public static string v1 { get; set; } public static int v2 { get; set; } private void timer1_Tick(object sender, EventArgs e) { label1.Text = v1; progressBar1.Value = v2; } } }
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
C#實(shí)現(xiàn)自定義windows系統(tǒng)日志的方法
這篇文章主要介紹了C#實(shí)現(xiàn)自定義windows系統(tǒng)日志的方法,涉及C#針對(duì)windows系統(tǒng)日志的創(chuàng)建、讀寫及刪除技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-08-08WPF使用DrawingContext實(shí)現(xiàn)二維繪圖
這篇文章介紹了WPF使用DrawingContext實(shí)現(xiàn)二維繪圖的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06Unity UGUI的EventTrigger事件監(jiān)聽器組件介紹使用示例
這篇文章主要為大家介紹了Unity UGUI的EventTrigger事件監(jiān)聽器組件介紹及使用,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08C#實(shí)現(xiàn)Word和ODT文檔相互轉(zhuǎn)換詳解
ODT文檔格式一種開放文檔格式(OpenDocument Text)。本文以C#及VB.NET代碼展示ODT和Word文檔之間相互轉(zhuǎn)換的方法,感興趣的可以學(xué)習(xí)一下2022-05-05C# WPF利用Clip屬性實(shí)現(xiàn)截屏框功能
這篇文章主要為大家詳細(xì)介紹了C# WPF如何利用Clip屬性實(shí)現(xiàn)截屏框功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-01-01