ImagePointControl.cs
5.6 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TSA_V.Common;
using TSA_V.DeviceLibrary;
using System.Drawing.Drawing2D;
namespace UserFromControl
{
public partial class ImagePointControl : UserControl
{
public ImagePointControl()
{
InitializeComponent();
}
public int selectIndex = 0;
public bool ImageNormal = true;
public bool ShowName = true;
private float imageXiShu = 1;
public double CurrBeiLu = 1;
private Image PicImage = null;
private List<SMTPointInfo> PointList = new List<SMTPointInfo>();
private int Width = 0;
private int Height = 0;
public void SetImage(Image image)
{
picBoard.Image = image;
this.PicImage = image;
}
public void LoadPoint(int width, int height, List<SMTPointInfo> pointList = null )
{
this.PointList = pointList;
Width = width;
Height = height;
CurrBeiLu = 1;
//picBoard.SizeMode = PictureBoxSizeMode.AutoSize;
if (pointList == null)
{
return;
}
if (!ImageNormal)
{
picBoard.Width = picBoard.Image.Width;
picBoard.Height = picBoard.Image.Height;
}
else
{
int xishu = 100;
picBoard.Width = width * xishu;
picBoard.Height = height * xishu;
if (picBoard.Width > panBoard.Width)
{
picBoard.Height = height * xishu * panBoard.Width / (width * xishu);
picBoard.Width = panBoard.Width;
}
if (picBoard.Height > panBoard.Height)
{
picBoard.Width = width * xishu * panBoard.Height / (height * xishu);
picBoard.Height = panBoard.Height;
}
}
//显示点
picBoard.Refresh();
panBoard.Refresh();
imageXiShu = (float)picBoard.Width / (float)width;
Graphics grfx = picBoard.CreateGraphics();
//float preX = 0;
//float preY = 0;
int index = 0;
foreach (SMTPointInfo weld in pointList)
{
float x = (float)Math.Abs(weld.PositionX) * imageXiShu;
float y = (float)Math.Abs(weld.PositionY) * imageXiShu;
int lineLength = 8;
Color color = Color.HotPink;
Brush brushes = Brushes.HotPink;
if (weld.CheckOK)
{
color = Color.Red;
brushes = Brushes.Red;
}
if (index.Equals(selectIndex))
{
color = Color.Orange;
brushes = Brushes.Orange;
}
grfx.DrawLine(new Pen(color, 2), x, y - lineLength, x, y + lineLength);
grfx.DrawLine(new Pen(color, 2), x - lineLength, y, x + lineLength, y);
//写字
if (index.Equals(selectIndex) || ShowName)
{
grfx.DrawString(weld.GetDisplayStr(), new Font("Arial ", 9, FontStyle.Bold), brushes, x - lineLength / 2 + 2, y + lineLength / 2 + 2);
}
index++;
}
grfx.SmoothingMode = SmoothingMode.HighQuality;
grfx.Dispose();
}
private void ImagePointControl_Load(object sender, EventArgs e)
{
picBoard.Tag = false;
picBoard.SizeMode = PictureBoxSizeMode.StretchImage;
picBoard.MouseWheel += picBoard_MouseWheel;
}
private void PicBoardBlowUp()
{
if (this.picBoard.Width > 5000 || this.picBoard.Height > 5000)
{
//不能继续放大
return;
}
float w = this.picBoard.Width * 1.2f; //每次放大 20%
float h = this.picBoard.Height * 1.2f;
CurrBeiLu = CurrBeiLu * 1.2f;
this.picBoard.Size = Size.Ceiling(new SizeF(w, h));
picBoard.Invalidate();
}
private void PicBoardShrink()
{
if (this.picBoard.Width < panBoard.Width && this.picBoard.Height < panBoard.Height)
{
//不能继续缩小
return;
}
float w = this.picBoard.Width * 0.8f; //每次縮小 20%
float h = this.picBoard.Height * 0.8f;
this.picBoard.Size = Size.Ceiling(new SizeF(w, h));
CurrBeiLu = CurrBeiLu * 0.8f;
}
void picBoard_MouseWheel(object sender, MouseEventArgs e)
{
this.picBoard.SizeMode = PictureBoxSizeMode.Zoom;
//向前
if (e.Delta > 0)
{
//PicBoardBlowUp();
}
//向后
else if (e.Delta < 0)
{
//PicBoardShrink();
}
}
//private void chbShowName_CheckedChanged(object sender, EventArgs e)
//{
// ShowName = chbShowName.Checked;
// LoadPoint(Width, Height, PointList);
//}
//private void chbNormal_CheckedChanged(object sender, EventArgs e)
//{
// ImageNormal = chbNormal.Checked;
// LoadPoint(Width, Height, PointList);
//}
}
}