-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCBlindButton.cs
136 lines (115 loc) · 4.34 KB
/
CBlindButton.cs
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
124
125
126
127
128
129
130
131
132
133
134
135
136
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace Ground_Floor
{
class CBlindButton
{
private PictureBox _BlindButton;
private List<Image> _lstImages;
private int _iTag;
private int _iValue;
private Panel _pnl;
public CDevices LinkedDevice;
public CBlindButton(int width, int height, int x, int y, Image imgOpen, Image imgClose, Image imgStop, Panel pnl, int tag, int iDefaultValue,CDevices devToBeLinked)
{
LinkedDevice = devToBeLinked;
// Tag & Value
_iValue = iDefaultValue;
_iTag = tag;
_pnl = pnl;
Size buttonSize = new Size(width, height);
_lstImages = new List<Image>();
_lstImages.Add(imgStop);
_lstImages.Add(imgClose);
_lstImages.Add(imgOpen);
_BlindButton = new PictureBox();
_BlindButton.Size = buttonSize;
_BlindButton.Location = new Point(x, y);
_BlindButton.Tag = _iTag;
_BlindButton.MouseDown +=new MouseEventHandler(_BlindButton_MouseDown);
_BlindButton.MouseUp +=new MouseEventHandler(_BlindButton_MouseUp);
changeStatus(iDefaultValue);
// Add the componenets to the Panel
pnl.Controls.Add(_BlindButton);
}
// Global
public CBlindButton(int width, int height, int x, int y, Image imgOpen, Image imgClose, Image imgStop, Panel pnl, int tag, int iDefaultValue)
{
// Tag & Value
_iValue = iDefaultValue;
_iTag = tag;
_pnl = pnl;
Size buttonSize = new Size(width, height);
_lstImages = new List<Image>();
_lstImages.Add(imgStop);
_lstImages.Add(imgClose);
_lstImages.Add(imgOpen);
_BlindButton = new PictureBox();
_BlindButton.Size = buttonSize;
_BlindButton.Location = new Point(x, y);
_BlindButton.Tag = _iTag;
_BlindButton.MouseDown += new MouseEventHandler(_BlindButton_MouseDown);
_BlindButton.MouseUp += new MouseEventHandler(_GlobalButton_MouseUp);
changeStatus(iDefaultValue);
// Add the componenets to the Panel
pnl.Controls.Add(_BlindButton);
}
private void _BlindButton_MouseDown(object sender, MouseEventArgs e)
{
int[] aryMinRanges = new int[3] { 89, 0, 176 };
int[] aryMaxRanges = new int[3] { 155, 66, 241 };
int iMousePosition = Form.MousePosition.X - (_BlindButton.Left + _pnl.Left + _pnl.Parent.Left);
for (int iStatus = 0; iStatus < 3; iStatus++)
{
if ((iMousePosition > aryMinRanges[iStatus]) && (iMousePosition < aryMaxRanges[iStatus]))
{
changeStatus(iStatus); // 0->Stop , 1->Open, 2->Close
}
}
}
private void changeStatus(int iStatus)
{
_iValue = iStatus;
_BlindButton.Image = _lstImages[iStatus];
}
private int getValue()
{
return _iValue;
}
private void _BlindButton_MouseUp(object sender, MouseEventArgs e)
{
_iValue = getValue();
switch (_iValue)
{
case 0: // Stop
LinkedDevice.TCInterface.SetBool(LinkedDevice.lstPrm[3], true);
break;
case 1: // Close
LinkedDevice.TCInterface.SetBool(LinkedDevice.lstPrm[2], true);
break;
case 2: // Open
LinkedDevice.TCInterface.SetBool(LinkedDevice.lstPrm[1], true);
break;
}
}
private void _GlobalButton_MouseUp(object sender, MouseEventArgs e)
{
_iValue = getValue();
switch (_iValue)
{
case 0: // Stop
//
break;
case 1: // Close
//
break;
case 2: // Open
//
break;
}
}
}
}