using System; using System.Drawing; using System.Windows.Forms; namespace Bro.UI.Model.Winform { public partial class IOIndicatorCtrl : UserControl { public IOIndicatorCtrl() { InitializeComponent(); } private bool? isON = null; public bool? IsOn { get => isON; set { bool? temp = isON; isON = value; if (temp != isON) { RefreshStatus(); } } } private void RefreshStatus() { if (InvokeRequired) { Invoke(new Action(() => RefreshStatus())); } else { plStatus.Invalidate(); } } private string desc = ""; public string Desc { get => desc; set { desc = value; DisplayDesc(); } } private void DisplayDesc() { if (InvokeRequired) { Invoke(new Action(() => DisplayDesc())); } else { lblDesc.Text = Desc; } } readonly PointF[] regionBlink = new PointF[] { new PointF(5,10), new PointF(10,13), new PointF(12,7), new PointF(10,5) }; public IOIndicatorCtrl(bool _isOn, string _desc) { InitializeComponent(); IsOn = _isOn; Desc = _desc; } private void plStatus_Paint(object sender, PaintEventArgs e) { Panel pl = sender as Panel; Graphics g = e.Graphics; g.Clear(System.Drawing.SystemColors.Control); if (IsOn != null) { if (IsOn.Value) { g.FillEllipse(Brushes.LightGreen, pl.ClientRectangle); } else { g.FillEllipse(Brushes.Gray, pl.ClientRectangle); } g.FillPolygon(Brushes.White, regionBlink); } } public event Action OnIODoubleClick; private void lblDesc_DoubleClick(object sender, EventArgs e) { if (IsOn != null) { OnIODoubleClick?.Invoke(Name,IsOn.Value); } } private void plStatus_DoubleClick(object sender, EventArgs e) { if (IsOn != null) { OnIODoubleClick?.Invoke(Name, IsOn.Value); } } } }