领胜LDS 键盘AOI检测项目
wells.liu
2020-07-10 562fe6d0615eecf92a7e5c5edf9d316f8295b199
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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<string,bool> OnIODoubleClick;
 
        private void lblDesc_DoubleClick(object sender, EventArgs e)
        {
            if (IsOn != null)
            {
                OnIODoubleClick?.Invoke(Desc,IsOn.Value);
            }
        }
 
        private void plStatus_DoubleClick(object sender, EventArgs e)
        {
            if (IsOn != null)
            {
                OnIODoubleClick?.Invoke(Desc, IsOn.Value);
            }
        }
    }
}