c#winform窗口頁面一打開就加載的實現(xiàn)方式
更新時間:2023年06月16日 10:52:42 作者:zzn的進(jìn)階筆記
這篇文章主要介紹了c#winform窗口頁面一打開就加載的實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
c#winform窗口頁面一打開就加載
//頁面一打開就加載這個方法 this.Load += new EventHandler(SQLGetTime_Load);
文本框設(shè)置默認(rèn)值,一打開就顯示
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è)置默認(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)包含三個部分(調(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++調(diào)用C#的DLL程序?qū)崿F(xiàn)方法
本文通過例子,講述了C++調(diào)用C#的DLL程序的方法,作出了以下總結(jié),具有一定的參考價值,下面就讓我們一起來學(xué)習(xí)吧2015-10-10

