dkStatusStrip.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:dkStatusStrip.cs
  5. * 2.功能描述:扩展的控件
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈晓野 2014/08/13 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.ComponentModel;
  12. using System.Drawing;
  13. using System.Windows.Forms;
  14. namespace Dongke.IBOSS.PRD.Basics.BaseControls
  15. {
  16. public partial class dkStatusStrip : StatusStrip
  17. {
  18. #region 成员变量
  19. private ToolStripStatusLabel lblTitle = null; // 消息Lable
  20. private ToolStripStatusLabel lblImage = null; // 通信状态图片、状态Lable
  21. private ToolStripStatusLabel lblTime = null; // 时间Lable
  22. private bool _isCommunicate; // 通信状态
  23. private bool _isTimer = true; // 时间Lable
  24. private string _statusText = " 通信中···"; // 通信状态文本
  25. #endregion
  26. #region 实例化
  27. public dkStatusStrip()
  28. {
  29. InitializeComponent();
  30. lblTitle = new ToolStripStatusLabel();
  31. lblTitle.BackgroundImage = global::Dongke.IBOSS.PRD.Basics.BaseControls.Resource.bg;
  32. lblImage = new ToolStripStatusLabel();
  33. lblImage.BackgroundImage = global::Dongke.IBOSS.PRD.Basics.BaseControls.Resource.bg;
  34. lblTime = new ToolStripStatusLabel();
  35. lblTime.BackgroundImage = global::Dongke.IBOSS.PRD.Basics.BaseControls.Resource.bg;
  36. this.Init();
  37. }
  38. #endregion
  39. #region 控件公开属性
  40. /// <summary>
  41. /// 通信状态的设定和取得
  42. /// </summary>
  43. [DefaultValue("True")]
  44. [Description("通信状态的设定和取得。")]
  45. public bool IsCommunicate
  46. {
  47. get
  48. {
  49. return _isCommunicate;
  50. }
  51. set
  52. {
  53. _isCommunicate = value;
  54. if (_isCommunicate)
  55. {
  56. StartCommunicate();
  57. }
  58. else
  59. {
  60. StopCommunicate();
  61. }
  62. }
  63. }
  64. /// <summary>
  65. /// 状态栏消息Lable的值设定和取得
  66. /// </summary>
  67. [DefaultValue("状态栏消息")]
  68. [Description("状态栏消息Lable的值设定和取得。")]
  69. public string TitleText
  70. {
  71. get
  72. {
  73. return lblTitle.Text;
  74. }
  75. set
  76. {
  77. SetTitleText(value);
  78. }
  79. }
  80. /// <summary>
  81. /// 时间lable是否显示
  82. /// </summary>
  83. [DefaultValue("True")]
  84. public bool IsTimer
  85. {
  86. get
  87. {
  88. return this._isTimer;
  89. }
  90. set
  91. {
  92. this._isTimer = value;
  93. if (value)
  94. {
  95. this.timerDateText.Interval = ControlsConst.TIMER_INTERVAL;
  96. this.timerDateText.Start();
  97. }
  98. else
  99. {
  100. this.timerDateText.Stop();
  101. this.lblTime.Text = string.Empty;
  102. }
  103. }
  104. }
  105. /// <summary>
  106. /// 状态栏通信状态Lable的值设定和取得
  107. /// </summary>
  108. [Browsable(true)]
  109. [Description("状态栏通信状态Lable的值设定和取得。")]
  110. public string StatusText
  111. {
  112. get
  113. {
  114. return _statusText;
  115. }
  116. set
  117. {
  118. this._statusText = value;
  119. SetStatusText(this._statusText);
  120. }
  121. }
  122. #endregion 控件公开属性
  123. #region 私有方法和函数
  124. /// <summary>
  125. /// 控件初始化
  126. /// </summary>
  127. private void Init()
  128. {
  129. // 状态栏消息Lable
  130. lblTitle.Text = "状态栏消息";
  131. lblTitle.Spring = true;
  132. lblTitle.TextAlign = ContentAlignment.MiddleLeft;
  133. // 通信状态图片、状态Lable
  134. lblImage.Text = "";
  135. lblImage.TextAlign = ContentAlignment.MiddleCenter;
  136. // 时间Lable
  137. if (_isTimer)
  138. {
  139. lblTime.Text = DateTime.Now.ToString(ControlsConst.DATETIME_FORMAT_YYYYMMDDHHMM);
  140. lblTime.TextAlign = ContentAlignment.MiddleRight;
  141. }
  142. else
  143. {
  144. lblTime.Text = string.Empty;
  145. lblTime.TextAlign = ContentAlignment.MiddleRight;
  146. }
  147. this.Items.Add(lblTitle);
  148. this.Items.Add(lblImage);
  149. this.Items.Add(lblTime);
  150. // 刷新时间Lable
  151. if (_isTimer)
  152. {
  153. this.timerDateText.Interval = ControlsConst.TIMER_INTERVAL;
  154. this.timerDateText.Start();
  155. }
  156. }
  157. /// <summary>
  158. /// 开始通讯
  159. /// </summary>
  160. private void StartCommunicate()
  161. {
  162. // 通信中
  163. SetStatusText(_statusText);
  164. // 通信中图片
  165. lblImage.Image = Dongke.IBOSS.PRD.Basics.BaseResources.Icon.communicating;
  166. }
  167. /// <summary>
  168. /// 结束通讯
  169. /// </summary>
  170. private void StopCommunicate()
  171. {
  172. try
  173. {
  174. if (this.InvokeRequired)
  175. {
  176. this.Invoke(new MethodInvoker(delegate()
  177. {
  178. StopCommunicate();
  179. }
  180. )
  181. );
  182. }
  183. else
  184. {
  185. lblImage.Image = null;
  186. lblImage.Text = "";
  187. }
  188. }
  189. catch (Exception ex)
  190. {
  191. throw (ex);
  192. }
  193. }
  194. /// <summary>
  195. /// 设置消息内容
  196. /// </summary>
  197. /// <param name="text"></param>
  198. private void SetTitleText(string text)
  199. {
  200. try
  201. {
  202. if (this.InvokeRequired)
  203. {
  204. this.Invoke(new MethodInvoker(delegate()
  205. {
  206. SetTitleText(text);
  207. }
  208. )
  209. );
  210. }
  211. else
  212. {
  213. lblTitle.Text = text;
  214. }
  215. }
  216. catch (Exception ex)
  217. {
  218. throw (ex);
  219. }
  220. }
  221. /// <summary>
  222. /// 设置状态文本
  223. /// </summary>
  224. /// <param name="status"></param>
  225. private void SetStatusText(string status)
  226. {
  227. try
  228. {
  229. if (this.InvokeRequired)
  230. {
  231. this.Invoke(new MethodInvoker(delegate()
  232. {
  233. SetStatusText(status);
  234. }
  235. )
  236. );
  237. }
  238. else
  239. {
  240. if (_isCommunicate)
  241. {
  242. this.lblImage.Text = this._statusText;
  243. }
  244. }
  245. }
  246. catch (Exception ex)
  247. {
  248. throw (ex);
  249. }
  250. }
  251. #endregion 私有方法和函数
  252. #region 事件
  253. /// <summary>
  254. /// 刷新时间
  255. /// </summary>
  256. /// <param name="sender"></param>
  257. /// <param name="e"></param>
  258. private void timerDateText_Tick(object sender, EventArgs e)
  259. {
  260. this.lblTime.Text = DateTime.Now.ToString(ControlsConst.DATETIME_FORMAT_YYYYMMDDHHMM);
  261. }
  262. #endregion 事件
  263. }
  264. }