c#winform窗口頁面一打開就加載的實現(xiàn)方式
更新時間:2023年06月16日 10:52:42 作者:zzn的進階筆記
這篇文章主要介紹了c#winform窗口頁面一打開就加載的實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
c#winform窗口頁面一打開就加載
//頁面一打開就加載這個方法 this.Load += new EventHandler(SQLGetTime_Load);
文本框設(shè)置默認值,一打開就顯示
private String text1 = "主賬薄";
private String text2 = "機器設(shè)備";
private String text3 = "JQSB0000001";
private String text4 = "打印機JQSB000001";
private String text5 = "臺";
private String text6 = "數(shù)量";
private String text7 = "2002-02-02";
private String text8 = "";
private String text9 = "經(jīng)營用";
private String text10 = "正常使用";
private String text11 = "購入";
private String text12 = "";
private String text13 = "";
private String text14 = "";
public void SetAttribute()
{
textBox1.Text = text1;//設(shè)置默認值
textBox2.Text = text2;//設(shè)置默認值
textBox3.Text = text3;//設(shè)置默認值
textBox4.Text = text4;//設(shè)置默認值
textBox4.Text = text4;//設(shè)置默認值
textBox5.Text = text5;//設(shè)置默認值
textBox6.Text = text6;//設(shè)置默認值
dateTimePicker1.Text = text7;//設(shè)置默認值
textBox8.Text = text8;//設(shè)置默認值
textBox9.Text = text9;//設(shè)置默認值
textBox10.Text = text10;//設(shè)置默認值
textBox11.Text = text11;//設(shè)置默認值
textBox12.Text = text12;//設(shè)置默認值
textBox13.Text = text13;//設(shè)置默認值
textBox14.Text = text14;//設(shè)置默認值
//MessageBox.Show("成功");
}
private void SQLGetTime_Load(object sender, EventArgs e)
{
SetAttribute();//窗體一加載就設(shè)置文本框的默認狀態(tài),
}c#winform加載界面
先上效果圖

代碼結(jié)構(gòu)包含三個部分(調(diào)用方-主線程,被調(diào)用方-加載顯示的界面,一個靜態(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)用方的界面(界面中有一個定時器 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é)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
C#實現(xiàn)自定義windows系統(tǒng)日志的方法
這篇文章主要介紹了C#實現(xiàn)自定義windows系統(tǒng)日志的方法,涉及C#針對windows系統(tǒng)日志的創(chuàng)建、讀寫及刪除技巧,非常具有實用價值,需要的朋友可以參考下2015-08-08
WPF使用DrawingContext實現(xiàn)二維繪圖
這篇文章介紹了WPF使用DrawingContext實現(xiàn)二維繪圖的方法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06
Unity UGUI的EventTrigger事件監(jiān)聽器組件介紹使用示例
這篇文章主要為大家介紹了Unity UGUI的EventTrigger事件監(jiān)聽器組件介紹及使用,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-08-08
C#實現(xiàn)Word和ODT文檔相互轉(zhuǎn)換詳解
ODT文檔格式一種開放文檔格式(OpenDocument Text)。本文以C#及VB.NET代碼展示ODT和Word文檔之間相互轉(zhuǎn)換的方法,感興趣的可以學(xué)習(xí)一下2022-05-05

