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);
                }
            }
    
        }
    }
    

      

  • 相关阅读:
    2017年6月笔记
    2017年5月笔记
    2017年4月笔记
    转发:i p _ f o r w a r d函数
    IP分组
    IP协议首部结构介绍
    IP:网际协议
    sed工具使用
    正则表达式匹配
    TCP的半连接
  • 原文地址:https://www.cnblogs.com/nymz/p/14153736.html
Copyright © 2011-2022 走看看