自定义的类实现状态栏时间和网络状态的变化
自定义的类实现状态栏时间和网络状态的变化 //qjh2008 by 2011-08 //事件,委托,自动更新,类,oo //更新状态栏 public delegate void UpdateStatusStrip(int index,string str); //主窗体中 private void UpdateStatus(int Index, string str) { if (InvokeRequired) Invoke(new UpdateStatusStrip(UpdateStatus), Index, str); else { statusStrip1.Items[Index].Text = str; } } //自定义的状态栏 class MyStatusStrip { // System.Timers.Timer myTimer; public event UpdateStatusStrip UpdateStatus; MyClient MastClient;//网络连接客户端 /// <summary> /// 构造函数 /// </summary> /// <param name="strip"></param> public MyStatusStrip(StatusStrip strip,MyClient client) { MastClient = client; InitCtrl(); } ~MyStatusStrip() { myTimer.Enabled = false; } ///网络状态 public string netStatus { get { string re = ""; if (MastClient == null) { return "未连接"; } switch (MastClient.myState) { case 0: re = "无连接"; break; case 1: re = "已连接"; break; case 2: re = "忙碌"; break; } return re; } } void myTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { //间隔事件 // ToolStripItem myitem6 = new ToolStripStatusLabel(System.DateTime.Now.ToShortTimeString()); //myStatus.Items[5].Text = System.DateTime.Now.ToShortTimeString(); //myStatus.Items[7].Text = netStatus; UpdateStatus(5, System.DateTime.Now.ToShortTimeString()); UpdateStatus(7, netStatus); } /// <summary> /// 初始化控件 /// </summary> private void InitCtrl() { try { myTimer = new System.Timers.Timer(1000); myTimer.Elapsed += new System.Timers.ElapsedEventHandler(myTimer_Elapsed); myTimer.Enabled = true; } catch (Exception er) { } } }
//事件,委托,自动更新,类,oo
//更新状态栏
public delegate void UpdateStatusStrip(int index,string str);
//主窗体中
private void UpdateStatus(int Index, string str)
{
if (InvokeRequired)
Invoke(new UpdateStatusStrip(UpdateStatus), Index, str);
else
{
statusStrip1.Items[Index].Text = str;
}
}
//自定义的状态栏
class MyStatusStrip
{
//
System.Timers.Timer myTimer;
public event UpdateStatusStrip UpdateStatus;
- 粉丝: 3
- 资源: 54
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助