using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading.Tasks;
using System.Threading;
namespace BestUseEventDeleagteWindow
{
public partial class Form1 : Form
{
public delegate void MyTimedel(DateTime dt);
public event MyTimedel EvetntDT;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
EvetntDT += new MyTimedel(C_dateTime);
//Thread th = new Thread(OnEvent);
//th.Start();
OnEvent();
}
public void C_dateTime(DateTime Cdt)
{
DateTime dt = Cdt;
if (this.lbltime.InvokeRequired)
{
MyTimedel d = new MyTimedel(C_dateTime);
this.Invoke(d, new object[] { Cdt });
}
else
{
this.lbltime.Text = dt.ToString();
// OnEvent();
}
}
protected void OnEvent()
{
if (EvetntDT != null)
{
C_dateTime(DateTime.Now);
}
}
private void button1_Click(object sender, EventArgs e)
{
OnEvent();
}
}
}
Comments
Post a Comment