c#winform窗口页面一打开就加载的实现方式

 更新时间:2023年06月16日 10:52:42   作者: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;
        }
    }
}

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。 

相关文章

  • c# linq的差集,并集,交集,去重代码(分享)

    c# linq的差集,并集,交集,去重代码(分享)

    下面小编就为大家分享一篇c# linq的差集,并集,交集,去重代码,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2017-11-11
  • Unity3d实现无限循环滚动背景

    Unity3d实现无限循环滚动背景

    这篇文章主要为大家详细介绍了Unity3d实现无限循环滚动背景,一个完整的商店广告牌组件,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-01-01
  • C#实现高效读写Excel工作表

    C#实现高效读写Excel工作表

    Excel 是各行业数据管理的核心载体,广泛应用于财务统计、库存管理、报表生成等场景,本文主要介绍了C#如何借助免费库 Free Spire.XLS for .NET实现读写 Excel 工作表,有需要的可以了解下
    2025-10-10
  • C#实现子类与父类的相互转换

    C#实现子类与父类的相互转换

    这篇文章主要介绍了C#实现子类与父类的相互转换,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-05-05
  • C#开发教程之ftp操作方法整理

    C#开发教程之ftp操作方法整理

    这篇文章主要介绍了C#开发教程之ftp操作方法整理的相关资料,需要的朋友可以参考下
    2016-07-07
  • C#实现Modbus通信功能的示例详解

    C#实现Modbus通信功能的示例详解

    Modbus作为一种开放且广泛采用的通信协议,在实现设备间数据交换方面发挥着至关重要的作用,它不仅支持多种物理层接口(如RS-232, RS-485, 以及以太网),还因其简单易用的特点而被大家所青睐,本文通过实际示例介绍如何在C#项目中轻松实现Modbus通信功能
    2024-11-11
  • c# BackgroundWorker组件的作用

    c# BackgroundWorker组件的作用

    这篇文章主要介绍了c# BackgroundWorker组件的作用,帮助大家更好的理解和使用c#编程语言,感兴趣的朋友可以了解下
    2020-12-12
  • C++调用C#的DLL程序实现方法

    C++调用C#的DLL程序实现方法

    本文通过例子,讲述了C++调用C#的DLL程序的方法,作出了以下总结,具有一定的参考价值,下面就让我们一起来学习吧
    2015-10-10
  • 事务在c#中的使用

    事务在c#中的使用

    这篇文章介绍了事务在c#中的使用,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-05-05
  • 如何用C#创建用户自定义异常浅析

    如何用C#创建用户自定义异常浅析

    虽然在 C# 语言中已经提供了很多异常处理类,但在实际编程中还是会遇到未涉及的一些异常处理,这篇文章主要给大家介绍了关于如何用C#创建用户自定义异常的相关资料,需要的朋友可以参考下
    2021-06-06

最新评论