using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.Drawing; using System.ComponentModel; namespace Mesnac.Controls.Default { /// /// 时间标签控件 /// [ToolboxBitmap(typeof(System.Windows.Forms.Timer))] public class DateTimeLabel : Label { private Timer timer; private int _interval = 500; private string _format = "yyyy-MM-dd HH:mm:ss"; public DateTimeLabel() { timer = new Timer(); timer.Interval = this._interval; timer.Tick += new EventHandler(timer_Tick); timer.Enabled = true; } protected void timer_Tick(object sender, EventArgs e) { if (this.DesignMode == false) { if (String.IsNullOrEmpty(this._format)) { this.Text = String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now); } else { try { this.Text = String.Format("{0:" + this._format + "}", DateTime.Now); } catch { } } } } /// /// 变化时间间隔 /// [Description("变化时间间隔"), Category("Appearance")] public int Interval { get { return _interval; } set { _interval = value; } } /// /// 格式 /// [Description("显示时间的格式"), Category("Appearance")] public string Format { get { return _format; } set { _format = value; } } } }