| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- /*******************************************************************************
- * 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 控件公开属性
- /// <summary>
- /// 通信状态的设定和取得
- /// </summary>
- [DefaultValue("True")]
- [Description("通信状态的设定和取得。")]
- public bool IsCommunicate
- {
- get
- {
- return _isCommunicate;
- }
- set
- {
- _isCommunicate = value;
- if (_isCommunicate)
- {
- StartCommunicate();
- }
- else
- {
- StopCommunicate();
- }
- }
- }
- /// <summary>
- /// 状态栏消息Lable的值设定和取得
- /// </summary>
- [DefaultValue("状态栏消息")]
- [Description("状态栏消息Lable的值设定和取得。")]
- public string TitleText
- {
- get
- {
- return lblTitle.Text;
- }
- set
- {
- SetTitleText(value);
- }
- }
- /// <summary>
- /// 时间lable是否显示
- /// </summary>
- [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;
- }
- }
- }
- /// <summary>
- /// 状态栏通信状态Lable的值设定和取得
- /// </summary>
- [Browsable(true)]
- [Description("状态栏通信状态Lable的值设定和取得。")]
- public string StatusText
- {
- get
- {
- return _statusText;
- }
- set
- {
- this._statusText = value;
- SetStatusText(this._statusText);
- }
- }
- #endregion 控件公开属性
- #region 私有方法和函数
- /// <summary>
- /// 控件初始化
- /// </summary>
- 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();
- }
- }
- /// <summary>
- /// 开始通讯
- /// </summary>
- private void StartCommunicate()
- {
- // 通信中
- SetStatusText(_statusText);
- // 通信中图片
- lblImage.Image = Dongke.IBOSS.PRD.Basics.BaseResources.Icon.communicating;
- }
- /// <summary>
- /// 结束通讯
- /// </summary>
- private void StopCommunicate()
- {
- try
- {
- if (this.InvokeRequired)
- {
- this.Invoke(new MethodInvoker(delegate()
- {
- StopCommunicate();
- }
- )
- );
- }
- else
- {
- lblImage.Image = null;
- lblImage.Text = "";
- }
- }
- catch (Exception ex)
- {
- throw (ex);
- }
- }
- /// <summary>
- /// 设置消息内容
- /// </summary>
- /// <param name="text"></param>
- 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);
- }
- }
- /// <summary>
- /// 设置状态文本
- /// </summary>
- /// <param name="status"></param>
- 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 事件
- /// <summary>
- /// 刷新时间
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void timerDateText_Tick(object sender, EventArgs e)
- {
- this.lblTime.Text = DateTime.Now.ToString(ControlsConst.DATETIME_FORMAT_YYYYMMDDHHMM);
- }
- #endregion 事件
- }
- }
|