/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:dkStatusStrip.cs * 2.功能描述:扩展的控件 * 编辑履历: * 作者 日期 版本 修改内容 * 陈晓野 2014/08/13 1.00 新建 *******************************************************************************/ using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; namespace Dongke.IBOSS.PRD.Basics.BaseControls { public partial class dkStatusStrip : StatusStrip { #region 成员变量 private ToolStripStatusLabel lblTitle = null; // 消息Lable private ToolStripStatusLabel lblImage = null; // 通信状态图片、状态Lable private ToolStripStatusLabel lblTime = null; // 时间Lable private bool _isCommunicate; // 通信状态 private bool _isTimer = true; // 时间Lable private string _statusText = " 通信中···"; // 通信状态文本 #endregion #region 实例化 public dkStatusStrip() { InitializeComponent(); lblTitle = new ToolStripStatusLabel(); lblTitle.BackgroundImage = global::Dongke.IBOSS.PRD.Basics.BaseControls.Resource.bg; lblImage = new ToolStripStatusLabel(); lblImage.BackgroundImage = global::Dongke.IBOSS.PRD.Basics.BaseControls.Resource.bg; lblTime = new ToolStripStatusLabel(); lblTime.BackgroundImage = global::Dongke.IBOSS.PRD.Basics.BaseControls.Resource.bg; this.Init(); } #endregion #region 控件公开属性 /// /// 通信状态的设定和取得 /// [DefaultValue("True")] [Description("通信状态的设定和取得。")] public bool IsCommunicate { get { return _isCommunicate; } set { _isCommunicate = value; if (_isCommunicate) { StartCommunicate(); } else { StopCommunicate(); } } } /// /// 状态栏消息Lable的值设定和取得 /// [DefaultValue("状态栏消息")] [Description("状态栏消息Lable的值设定和取得。")] public string TitleText { get { return lblTitle.Text; } set { SetTitleText(value); } } /// /// 时间lable是否显示 /// [DefaultValue("True")] public bool IsTimer { get { return this._isTimer; } set { this._isTimer = value; if (value) { this.timerDateText.Interval = ControlsConst.TIMER_INTERVAL; this.timerDateText.Start(); } else { this.timerDateText.Stop(); this.lblTime.Text = string.Empty; } } } /// /// 状态栏通信状态Lable的值设定和取得 /// [Browsable(true)] [Description("状态栏通信状态Lable的值设定和取得。")] public string StatusText { get { return _statusText; } set { this._statusText = value; SetStatusText(this._statusText); } } #endregion 控件公开属性 #region 私有方法和函数 /// /// 控件初始化 /// private void Init() { // 状态栏消息Lable lblTitle.Text = "状态栏消息"; lblTitle.Spring = true; lblTitle.TextAlign = ContentAlignment.MiddleLeft; // 通信状态图片、状态Lable lblImage.Text = ""; lblImage.TextAlign = ContentAlignment.MiddleCenter; // 时间Lable if (_isTimer) { lblTime.Text = DateTime.Now.ToString(ControlsConst.DATETIME_FORMAT_YYYYMMDDHHMM); lblTime.TextAlign = ContentAlignment.MiddleRight; } else { lblTime.Text = string.Empty; lblTime.TextAlign = ContentAlignment.MiddleRight; } this.Items.Add(lblTitle); this.Items.Add(lblImage); this.Items.Add(lblTime); // 刷新时间Lable if (_isTimer) { this.timerDateText.Interval = ControlsConst.TIMER_INTERVAL; this.timerDateText.Start(); } } /// /// 开始通讯 /// private void StartCommunicate() { // 通信中 SetStatusText(_statusText); // 通信中图片 lblImage.Image = Dongke.IBOSS.PRD.Basics.BaseResources.Icon.communicating; } /// /// 结束通讯 /// private void StopCommunicate() { try { if (this.InvokeRequired) { this.Invoke(new MethodInvoker(delegate() { StopCommunicate(); } ) ); } else { lblImage.Image = null; lblImage.Text = ""; } } catch (Exception ex) { throw (ex); } } /// /// 设置消息内容 /// /// private void SetTitleText(string text) { try { if (this.InvokeRequired) { this.Invoke(new MethodInvoker(delegate() { SetTitleText(text); } ) ); } else { lblTitle.Text = text; } } catch (Exception ex) { throw (ex); } } /// /// 设置状态文本 /// /// private void SetStatusText(string status) { try { if (this.InvokeRequired) { this.Invoke(new MethodInvoker(delegate() { SetStatusText(status); } ) ); } else { if (_isCommunicate) { this.lblImage.Text = this._statusText; } } } catch (Exception ex) { throw (ex); } } #endregion 私有方法和函数 #region 事件 /// /// 刷新时间 /// /// /// private void timerDateText_Tick(object sender, EventArgs e) { this.lblTime.Text = DateTime.Now.ToString(ControlsConst.DATETIME_FORMAT_YYYYMMDDHHMM); } #endregion 事件 } }