ucLamp.cs
1.99 KB
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MyControl
{
public partial class ucLamp : UserControl
{
public ucLamp()
{
InitializeComponent();
}
private int _display;
/// <summary>
/// 显示的值
/// </summary>
public int display
{
get
{
return _display;
}
set
{
if (value >= 0 && value <= Int16.MaxValue)
{
if (_display != value)
{
_display = value;
Lampdisplay(_display);
}
}
}
}
/// <summary>
/// 显示函数
/// </summary>
/// <param name="value"></param>
public void Lampdisplay(int value)
{
bool[] display = int2bools(value).Reverse().ToArray();
//绿灯 运行+空闲
picGreen.Visible = (display[0] == true || display[1] == true);
//蓝灯 通讯正常+计划保养
picBlue.Visible = (display[2] == true || display[3] == true);
//红灯 设备异常
picRed.Visible = (display[4] == true);
//黄灯 调机+警告
picYellow.Visible = (display[5] == true || display[6]);
}
/// <summary>
/// 16进制int转bool数组
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
private bool[] int2bools(int s)
{
char[] strs = Convert.ToString(s, 2).PadLeft(16, '0').ToCharArray();
bool[] re = new bool[16];
for (int i = 0; i < re.Length; i++)
{
re[i] = strs[i] == '1';
}
return re;
}
}
}