110,539
社区成员
发帖
与我相关
我的任务
分享
private void Reminder_Load(object sender, EventArgs e)//FormLoad事件
{
Control.CheckForIllegalCrossThreadCalls = false;//是否检查跨线程调用windows控件不安全?属性为 不检查
th = new Thread(new ThreadStart(getDateTime));
th.IsBackground = false;
th.Start();
}
public void getDateTime()//获取当前时间
{
while (true)
{
lblDateTime.Text = DateTime.Now.ToString();
Thread.Sleep(50);
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsApplication9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString();
}
}
}