zoukankan      html  css  js  c++  java
  • C#用委托来动态显示日期和时间

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace _01测试委托与事件
    {
    
        public delegate void DeShowTime();
    
     
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
    
                Thread thread = new Thread(ShowTime);
                thread.IsBackground = true;
                thread.Start();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                Control.CheckForIllegalCrossThreadCalls = false;
            }
    
            public void ShowTime()
            { 
                while (true)
                {
                    //Lambda表达式
                    //DeShowTime dst = () =>
                    //{
                    //    textBox1.Text = "当前时间:" + DateTime.Now.ToString();
                    //};
    
                    //匿名函数委托
                    DeShowTime dst = delegate
                    {
                        textBox1.Text =  DateTime.Now.ToString();
                        toolStripStatusLabel1.Text = "当前时间: " + DateTime.Now.ToString();
                    };
    
                    dst();
                    Thread.Sleep(1000);
                }
            }
    
        }
    }
    

      

  • 相关阅读:
    简单的多重背包
    完美子图
    活动投票
    人品问题
    售票系统
    最短路径
    优美值
    前端-常用函数记录-持续更新
    前端-单点登录中cookie中domain的思考
    大白话说GIT常用操作,常用指令git操作大全
  • 原文地址:https://www.cnblogs.com/nymz/p/14153736.html
Copyright © 2011-2022 走看看