c#winform窗口页面一打开就加载的实现方式
作者:zzn的进阶笔记
这篇文章主要介绍了c#winform窗口页面一打开就加载的实现方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
c#winform窗口页面一打开就加载
//页面一打开就加载这个方法 this.Load += new EventHandler(SQLGetTime_Load);
文本框设置默认值,一打开就显示
private String text1 = "主账薄"; private String text2 = "机器设备"; private String text3 = "JQSB0000001"; private String text4 = "打印机JQSB000001"; private String text5 = "台"; private String text6 = "数量"; private String text7 = "2002-02-02"; private String text8 = ""; private String text9 = "经营用"; private String text10 = "正常使用"; private String text11 = "购入"; private String text12 = ""; private String text13 = ""; private String text14 = ""; public void SetAttribute() { textBox1.Text = text1;//设置默认值 textBox2.Text = text2;//设置默认值 textBox3.Text = text3;//设置默认值 textBox4.Text = text4;//设置默认值 textBox4.Text = text4;//设置默认值 textBox5.Text = text5;//设置默认值 textBox6.Text = text6;//设置默认值 dateTimePicker1.Text = text7;//设置默认值 textBox8.Text = text8;//设置默认值 textBox9.Text = text9;//设置默认值 textBox10.Text = text10;//设置默认值 textBox11.Text = text11;//设置默认值 textBox12.Text = text12;//设置默认值 textBox13.Text = text13;//设置默认值 textBox14.Text = text14;//设置默认值 //MessageBox.Show("成功"); } private void SQLGetTime_Load(object sender, EventArgs e) { SetAttribute();//窗体一加载就设置文本框的默认状态, }
c#winform加载界面
先上效果图
代码结构包含三个部分(调用方-主线程,被调用方-加载显示的界面,一个静态类)
调用的方的界面
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> /// 关闭窗口 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { ThreadNewFrm.Close(); } } }
被调用方的界面(界面中有一个定时器 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> /// 关闭窗口 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { ThreadNewFrm.Close(); } } }
静态类
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; } } }
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。