FrmProjectorScreen.cs
13.2 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TSA_V.Common;
using TSA_V.DeviceLibrary;
namespace TSA_V
{
public partial class FrmProjectorScreen : Form
{
public static FrmProjectorScreen instance = new FrmProjectorScreen();
public FrmProjectorScreen()
{
InitializeComponent();
}
public int ScreenIndex = 1;
public int ScreenWidth = 1920;
public int ScreenHeight = 1280;
public int LastX = 0;
public int LastY = 0;
public int LastType = 1;
public int LastSizeX = 2;
public int LastSizeY = 2;
public bool ISShow = false;
// private bool hasShow = false;
private void FrmScreenTest_Load(object sender, EventArgs e)
{
this.Text = "显示测试_" + ScreenIndex;
this.StartPosition = FormStartPosition.Manual;
}
public bool CloseShowName=false;
public bool ShowForm()
{
Screen[] sc = Screen.AllScreens;
this.StartPosition = FormStartPosition.Manual;
this.WindowState = FormWindowState.Maximized;
if (sc.Count() > ScreenIndex)
{
Screen screen = sc[ScreenIndex];
foreach (Screen s in sc)
{
if (!s.Primary)
{
screen = s;
break;
}
}
string text = "名称:" + screen.DeviceName + "\r\n";
text += "Width:" + screen.Bounds.Width + "\r\n";
text += "Heigh:" + screen.Bounds.Height + "\r\n";
text += "是否主显示器:" + screen.Primary.ToString() + "\r\n";
//lblInfo.Text = text;
ScreenWidth = screen.Bounds.Width;
ScreenHeight = screen.Bounds.Height;
TSAVBean.X_Max = ScreenWidth;
TSAVBean.Y_Max = ScreenHeight;
TSAVBean.X_Min = 1;
TSAVBean.Y_Min = 1;
ISShow = true;
this.Location = new Point(screen.Bounds.Left, screen.Bounds.Top);
this.Show();
LogUtil.info("投影显示成功,屏幕索引=" + ScreenIndex + " !");
return true;
}
else
{
LogUtil.info("投影显示失败:屏幕索引=" + ScreenIndex + " 未找到");
return false;
}
}
private void FrmScreenTest_Shown(object sender, EventArgs e)
{
ShowPoint(new ProjectorPInfo( ScreenWidth / 2, ScreenHeight / 2));
DrawArea();
}
public void DrawArea()
{
if (!ISShow)
{
return;
}
int startX = 0;
int startY = 0;
int Point_X_Length = 3;
int Point_Y_Length = 3;
int lineWidth = (ScreenWidth ) / (Point_X_Length - 1);
int lineHeight = (ScreenHeight ) / (Point_Y_Length - 1);
Graphics grfx = panel1.CreateGraphics();
Color color = Color.White;
grfx.SmoothingMode = SmoothingMode.HighQuality;
//循环画线
for (int i = 0; i <= Point_X_Length; i++)
{
float line = 0.2F;
float picLocationX = startX + lineWidth * i;
if (picLocationX >= ScreenWidth)
{
picLocationX = ScreenWidth - 2;
}
grfx.DrawLine(new Pen(color, line), picLocationX, startY, picLocationX, ScreenHeight);
}
for (int i = 0; i <= Point_Y_Length; i++)
{
float line = 0.2F;
float picLocationY = startY + lineHeight * i;
if (picLocationY >= ScreenHeight)
{
picLocationY = ScreenHeight - 1;
}
grfx.DrawLine(new Pen(color, line), startX, picLocationY, ScreenWidth, picLocationY);
}
grfx.Dispose();
}
public void DrawLine()
{
if (!ISShow)
{
return;
}
int startX = 0;
int startY = 0;
int Point_X_Length = 21;
int Point_Y_Length = 21;
int lineWidth = (ScreenWidth - startX * 2) / (Point_X_Length-1);
int lineHeight = (ScreenHeight - startY * 2) / (Point_Y_Length-1);
Graphics grfx = panel1.CreateGraphics();
Color color = Color.White;
grfx.SmoothingMode = SmoothingMode.HighQuality;
//循环画线
for (int i = 0; i <= Point_X_Length; i++)
{
float line = 0.2F;
float picLocationX = startX + lineWidth * i;
if (i.Equals(Point_X_Length / 2))
{
line = 1;
}
else if (((i % 5).Equals(0)) && (i > 0) && (i < Point_X_Length))
{
line = 0.5F;
}
grfx.DrawLine(new Pen(color, line), picLocationX, startY, picLocationX, ScreenHeight);
}
for (int i = 0; i <= Point_Y_Length; i++)
{
float line = 0.2F;
float picLocationY = startY + lineHeight * i;
if (i.Equals(Point_Y_Length / 2))
{
line = 1;
}
else if (((i % 5).Equals(0)) && (i > 0) && (i < Point_Y_Length))
{
line = 0.5F;
}
grfx.DrawLine(new Pen(color, line), startX, picLocationY, ScreenWidth, picLocationY);
}
grfx.Dispose();
}
private Color CurrColor = Color.White;
public void ClearPoint()
{
if (!ISShow)
{
return;
}
Graphics g = this.panel1.CreateGraphics();
g.Clear(Color.Black);
g.Dispose();//释放资源
}
private void DrawPoint(Graphics g, int x, int y, int type = 0, int sizeX = 2, int sizeY = 2, int lineLength = 2, string name = "")
{
if (sizeX < 2)
{
sizeX = 2;
}
if (sizeY < 2)
{
sizeY = 2;
}
LastX = x;
LastY = y;
LastSizeX = sizeX;
LastSizeY = sizeY;
LastType = type;
Pen pen = new Pen(CurrColor, lineLength);
System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(CurrColor);
//点类型,1 = 点,2 = +,3 =|,4 = -,5 = 方形,6 = 圆圈
if (type.Equals(PointType_Define.PlusSign_2))
{
g.DrawLine(pen, new Point(x - sizeX, y), new Point(x + sizeX, y));
g.DrawLine(pen, new Point(x, y - sizeY), new Point(x, y + sizeY));
}
else if (type.Equals(PointType_Define.VerticalLine_3))
{
g.DrawLine(pen, new Point(x, y - sizeY), new Point(x, y + sizeY));
}
else if (type.Equals(PointType_Define.Line_4))
{
g.DrawLine(pen, new Point(x - sizeX, y), new Point(x + sizeX, y));
}
else if (type.Equals(PointType_Define.Rectangle_5))
{
g.DrawRectangle(pen, x - sizeX / 2, y - sizeY / 2, sizeX, sizeY);
}
else if (type.Equals(PointType_Define.Cycle_6))
{
g.DrawEllipse(pen, x - sizeX / 2, y - sizeY / 2, sizeX, sizeY);
}
else if (type.Equals(PointType_Define.Plus_Up_7))
{
int plusSize = sizeX / 2;
int pX = x;
int pY = y - sizeY / 2 - lineLength - plusSize;
g.DrawLine(pen, new Point(pX - plusSize, pY), new Point(pX + plusSize, pY));
g.DrawLine(pen, new Point(pX, pY - plusSize), new Point(pX, pY + plusSize));
g.DrawRectangle(pen, x - sizeX / 2, y - sizeY / 2, sizeX, sizeY);
}
else if (type.Equals(PointType_Define.Plus_Down_8))
{
g.DrawRectangle(pen, x - sizeX / 2, y - sizeY / 2, sizeX, sizeY);
int plusSize = sizeX / 2;
int pX = x;
int pY = y + sizeY / 2 + lineLength + plusSize;
g.DrawLine(pen, new Point(pX - plusSize, pY), new Point(pX + plusSize, pY));
g.DrawLine(pen, new Point(pX, pY - plusSize), new Point(pX, pY + plusSize));
}
else if (type.Equals(PointType_Define.Plus_Left_9))
{
g.DrawRectangle(pen, x - sizeX / 2, y - sizeY / 2, sizeX, sizeY);
int plusSize = sizeY / 2;
int pX = x - sizeX / 2 - lineLength - plusSize;
int pY = y;
g.DrawLine(pen, new Point(pX - plusSize, pY), new Point(pX + plusSize, pY));
g.DrawLine(pen, new Point(pX, pY - plusSize), new Point(pX, pY + plusSize));
}
else if (type.Equals(PointType_Define.Plus_Right_10))
{
g.DrawRectangle(pen, x - sizeX / 2, y - sizeY / 2, sizeX, sizeY);
int plusSize = sizeY / 2;
int pX = x + sizeX / 2 + lineLength + plusSize;
int pY = y;
g.DrawLine(pen, new Point(pX - plusSize, pY), new Point(pX + plusSize, pY));
g.DrawLine(pen, new Point(pX, pY - plusSize), new Point(pX, pY + plusSize));
}
else
{
g.FillEllipse(myBrush, new Rectangle(x - sizeX / 2, y - sizeY / 2, sizeX, sizeY));//画实心椭圆
}
if (!name.Equals(""))
{
int size = (sizeX + sizeY) / 2;
size = 30;
if (!CloseShowName)
{
g.DrawString(name, new Font("Arial ", size, FontStyle.Regular), Brushes.White, x - size + 5, y + size + 2);
}
}
}
public void ShowPoint(DeviceLibrary.ProjectorPInfo p )
{
if (!ISShow)
{
return;
}
Graphics g = panel1.CreateGraphics();
DrawPoint(g, p.PX,p.PY,p.PType,p.SizeX,p.SizeY,p.PenWidth, p.ShowText);
g.Dispose();
}
public void ShowPoint(bool showName , params SMTPointInfo[] points )
{
if (!ISShow)
{
return;
}
ClearPoint();
Graphics g = panel1.CreateGraphics();
foreach (SMTPointInfo point in points)
{
int type = point.PointType;
int x = (int)point.NodePositionX;
int y = (int)point.NodePositionY;
int sizex = point.PointSizeX;
int sizey = point.PointSizeY;
DrawPoint(g, x, y, type, sizex,sizey,point.PenWidth,"");
if (showName)
{
int size = (sizex + sizey) / 2;
if (!CloseShowName)
{
if (point.CheckOK && (points.Length > 1))
{
g.DrawString(point.ShowText, new Font("Arial ", size, FontStyle.Regular), Brushes.Red, x - size / 2 + 5, y + size / 2 + 2);
}
else
{
g.DrawString(point.ShowText, new Font("Arial ", size, FontStyle.Regular), Brushes.White, x - size / 2 + 5, y + size / 2 + 2);
}
}
}
}
g.Dispose();
}
}
public class PointType_Define
{
public static int None = 0;
/// <summary>
/// "1=●",
/// </summary>
public static int Point_1 = 1;
/// <summary>
/// "2=✚",
/// </summary>
public static int PlusSign_2 = 2;
/// <summary>
/// "3=┃",
/// </summary>
public static int VerticalLine_3 = 3;
/// <summary>
/// "4=━━",
/// </summary>
public static int Line_4 = 4;
/// <summary>
/// "5=□",
/// </summary>
public static int Rectangle_5 = 5;
/// <summary>
/// "6=○"
/// </summary>
public static int Cycle_6 = 6;
/// <summary>
/// "7=正极限_上方",
/// </summary>
public static int Plus_Up_7 = 7;
/// <summary>
/// "8=正极限_下方",
/// </summary>
public static int Plus_Down_8 = 8;
/// <summary>
/// "9=正极限_左方 ✚□",
/// </summary>
public static int Plus_Left_9 = 9;
/// <summary>
///"10=正极限_右方 □✚"
/// </summary>
public static int Plus_Right_10 = 10;
}
}