using System;
using System.Timers;
namespace TianYiHeWenQi
{
class HewenqiTianyi
{
public static event ActionEventHandler HoverTreeWindEvent;
WindEventArgs _arg = new WindEventArgs();
public HewenqiTianyi()
{
Timer h_timer = new Timer();
h_timer.Interval = 3000;
h_timer.Elapsed += H_timer_Elapsed;
h_timer.Start();
}
Random _HoverClock=new Random ();
private void H_timer_Elapsed(object sender, ElapsedEventArgs e)
{
_arg.WindType = (WindDdirection)(_HoverClock.Next(3));
OnAction(_arg);
}
protected void OnAction(WindEventArgs ev)
{
HoverTreeWindEvent?.Invoke(ev);
//相当于以下代码
//if (HoverTreeWindEvent != null)
//{
// HoverTreeWindEvent(ev);
//}
}
}
class WindEventArgs : EventArgs
{
public WindDdirection WindType { get; set; }
}
enum WindDdirection
{
East,
West,
Static
}
delegate void ActionEventHandler(WindEventArgs ev);
}
using System;
using System.Windows.Forms;
namespace TianYiHeWenQi
{
public partial class HoverTreeGrass : UserControl
{
delegate void MySetText(string text);
public HoverTreeGrass()
{
InitializeComponent();
HewenqiTianyi.HoverTreeWindEvent += HewenqiTianyi_HoverTreeWindEvent;
}
private void UpdateLabel(WindDdirection wd)
{
if (label_grass.InvokeRequired)
{
// 当一个控件的InvokeRequired属性值为真时,说明有一个创建它以外的线程想访问它
Action<WindDdirection> actionDelegate = (x) => {
switch (x)
{
case WindDdirection.East:
label_grass.Location = new System.Drawing.Point(40 - 9, label_grass.Location.Y);
label_grass.Text="\\";
break;
case WindDdirection.West:
label_grass.Location = new System.Drawing.Point(40+9, label_grass.Location.Y);
label_grass.Text = "/";
break;
case WindDdirection.Static:
label_grass.Location = new System.Drawing.Point(40, label_grass.Location.Y);
label_grass.Text = "|";
break;
}
};
// 或者
// Action<string> actionDelegate = delegate(string txt) { this.label_grass.Text = txt; };
this.label_grass.BeginInvoke(actionDelegate, wd);
}
else
{
switch (wd)
{
case WindDdirection.East:
label_grass.Text = "\\";
break;
case WindDdirection.West:
label_grass.Text = "/";
break;
case WindDdirection.Static:
label_grass.Text = "|";
break;
}
}
}
private void HewenqiTianyi_HoverTreeWindEvent(WindEventArgs ev)
{
UpdateLabel(ev.WindType);
}
}
}
using System.Windows.Forms;
namespace TianYiHeWenQi
{
public partial class HoverTreeForm : Form
{
public HoverTreeForm()
{
InitializeComponent();
for (int i = 0; i < tableLayoutPanel_hovertree.ColumnCount; i++) {
for (int j = 0; j < tableLayoutPanel_hovertree.RowCount; j++) {
tableLayoutPanel_hovertree.Controls.Add(new HoverTreeGrass(), i, j);
}
}
HewenqiTianyi h_ty = new HewenqiTianyi();
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有