form1.cs

来自「button delay 实现时间延迟功能」· CS 代码 · 共 38 行

CS
38
字号
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace button1Delay
{
    public partial class Form1 : Form
    {
        public delegate void 我的委托();//声明一个委托 
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            new System.Threading.Thread(new System.Threading.ThreadStart(新线程)).Start();//创建一个新的线程并启动 

        }
        public void 设置文字()
        {
            button1.Text = "Hello";
        }

        public void 新线程()
        {
            System.Threading.Thread.Sleep(2000);//线程休眠2秒 
            button1.BeginInvoke(new 我的委托(设置文字));//在button1所在线程上执行“设置文字” 


        } 

    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?