FrmBase.cs
11.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
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
using MetroFramework.Forms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TSA_V.Common;
namespace TSA_V
{
public partial class FrmBase : Form
{
internal static string GetVersion(bool IsShow = false)
{
string str = "";
string version = "";
DateTime newData = DateTime.Parse("2000-01-01");
try
{
System.Reflection.AssemblyName assemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName();
version = assemblyName.Version.ToString();
string[] strArray = version.Split('.');
if (strArray.Length.Equals(4))
{
int days = Convert.ToInt32(strArray[2]);
int seconds = Convert.ToInt32(strArray[3]);
DateTime d1 = DateTime.Parse("2000-01-01");
newData = d1.AddDays(days);
newData = newData.AddSeconds(seconds * 2);
str = newData.ToString("yyyy-MM-dd HH:mm");
}
}
catch (Exception ex)
{
str = version;
LogUtil.error("解析版本号【" + str + "】出错:"+ex.ToString());
}
if (IsShow)
{
LogUtil.info("版本号[" + version + "][" + str + "][Smart-Workstation][" + GetCodeNum() + "]");
}
return str;
}
internal static string GetCodeNum(string codeName = "Smart-Workstation")
{
byte[] byteArray = System.Text.Encoding.ASCII.GetBytes(codeName);
string result = "";
result = AcSerialBean.ByteToString(byteArray);
return result;
}
public string CurrLanguage = "";
public string ClassName
{
get
{
return this.GetType().Name;
}
set
{
}
}
public FrmBase()
{
InitializeComponent();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
// SetScreen();
//this.Resizable = false;
}
private void FrmBase_Load(object sender, EventArgs e)
{
ImageManager.frm_背景图 = global::TSA_V.Properties.Resources.背景图dark;
ProcessUI(this);
}
void ProcessUI(Control partentControl)
{
if (IsDesignMode())
return;
if (partentControl is FrmLogin || partentControl is FrmMenu || partentControl is FrmMaintenance)
{
partentControl.BackgroundImage = global::TSA_V.Properties.Resources.背景图dark;
}
if (partentControl is Form)
{
if ((partentControl as Form).WindowState == FormWindowState.Maximized)
{
(partentControl as Form).FormBorderStyle = FormBorderStyle.FixedSingle;
(partentControl as Form).WindowState = FormWindowState.Maximized;
//(partentControl as Form).Resize += FrmBase_Resize;
(partentControl as Form).Move += FrmBase_Resize;
}
(partentControl as Form).Icon = global::TSA_V.Properties.Resources.neo_station1;
(partentControl as Form).AutoScaleMode = AutoScaleMode.None;
}
partentControl.BackColor = Color.Black;//Color.FromArgb(53, 67, 88);
partentControl.ForeColor = Color.White;
foreach (Control con in partentControl.Controls)
{
con.BackColor = Color.Black; //Color.FromArgb(53, 67, 88);
con.ForeColor = Color.White;
if (con is ComboBox)
{
//(con as ComboBox).DrawMode = DrawMode.OwnerDrawVariable;
}
if (con is ComboBox || con is TextBox)
{
//con.BackColor = Color.Black;//Color.FromArgb(160, 165, 172);
//con.ForeColor = Color.White; //Color.FromArgb(0, 0, 40); ;
con.BackColor = Color.White;//Color.FromArgb(160, 165, 172);
con.ForeColor = Color.Black; //Color.FromArgb(0, 0, 40); ;
}
if (con is LinkLabel)
{
(con as LinkLabel).LinkColor = Color.White;
}
if (con is DataGridView)
{
con.ForeColor = Color.Black;
continue;
}
if (con.Controls.Count > 0)
{
ProcessUI(con);
}
}
}
private void FrmBase_Resize(object sender, EventArgs e)
{
(sender as Form).Width = Screen.PrimaryScreen.WorkingArea.Width;
(sender as Form).Height = Screen.PrimaryScreen.WorkingArea.Height;
//(sender as Form).WindowState = FormWindowState.Maximized;
}
public static bool IsDesignMode()
{
bool returnFlag = false;
if (Process.GetCurrentProcess().ProcessName == "devenv")
{
returnFlag = true;
}
return returnFlag;
}
/// <summary>
/// 引用user32.dll动态链接库(windows api),
/// 使用库中定义 API:SetCursorPos
/// </summary>
[DllImport("user32.dll")]
private static extern int SetCursorPos(int x, int y);
/// <summary>
/// 移动鼠标到指定的坐标点
/// </summary>
public void MoveMouseToPoint(Point p)
{
SetCursorPos(p.X, p.Y);
}
/// <summary>
/// 设置鼠标的移动范围
/// </summary>
public void SetMouseRectangle(Rectangle rectangle)
{
System.Windows.Forms.Cursor.Clip = rectangle;
}
/// <summary>
/// 设置鼠标位于屏幕中心
/// </summary>
public void SetMouseAtCenterScreen()
{
int winHeight = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
int winWidth = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
Point centerP = new Point(winWidth / 2, winHeight / 2);
MoveMouseToPoint(centerP);
}
public void SetSkin(FrmBase preCon)
{
}
public void LanguageProcess()
{
if (CurrLanguage.Equals(ResourceCulture.CurrLanguage))
{
return;
}
string className = this.ClassName;
CurrLanguage = ResourceCulture.CurrLanguage;
this.Text = ResourceCulture.GetString(ResourceCulture.GetTextIdStr(className), this.Text);
if (this is FrmMenu)
{
FrmMenu frm = (FrmMenu)this;
frm.LoadBackImage();
}
else if (this is FrmWorkMenu)
{
FrmWorkMenu frm = (FrmWorkMenu)this;
frm.LoadBackImage();
}
else
{
foreach (Control con in this.Controls)
{
if (con is Label || con is Button || con is RadioButton || con is CheckBox)
{
string newStr = ResourceCulture.GetString(ResourceCulture.GetTextIdStr(className, con.Name), con.Text);
con.Text = newStr;
con.Tag = newStr;
if (con is Button && (!(this is FrmMenu)) && (!(this is FrmMaintenance)) && (!(this is FrmWorkMenu)))
//if (con is Button && (this is FrmWork))
{
if (ResourceCulture.CurrLanguage.Equals(ResourceCulture.English))
{
con.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
}
else
{
con.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
}
}
// con.Refresh();
}
else if (con.Controls.Count > 0)
{
PreControlLanaguage(con);
}
}
}
}
private void PreControlLanaguage(Control partentControl)
{
string className = this.ClassName;
if(partentControl is NumericUpDown)
{
return;
}
partentControl.Text = ResourceCulture.GetString(ResourceCulture.GetTextIdStr(className, partentControl.Name), partentControl.Text);
foreach (Control con in partentControl.Controls)
{
if (con is Label || con is Button || con is RadioButton || con is CheckBox)
{
string newStr = ResourceCulture.GetString(ResourceCulture.GetTextIdStr(className, con.Name), con.Text);
con.Text = newStr;
if (con is Button && (!(this is FrmMenu)) && (!(this is FrmMaintenance)) && (!(this is FrmWorkMenu)) && (!(this is FrmIoManager)))
{
if (ResourceCulture.CurrLanguage.Equals(ResourceCulture.English))
{
con.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
}
else
{
con.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
}
}
// con.Refresh();
}
else if (con.Controls.Count > 0)
{
PreControlLanaguage(con);
}
}
}
private void FrmBase_VisibleChanged(object sender, EventArgs e)
{
if (this.Visible.Equals(true))
{
LanguageProcess();
}
}
protected void SetScreen(int index = -1)
{
Screen[] sc = Screen.AllScreens;
this.StartPosition = FormStartPosition.Manual;
if (sc.Count() > index)
{
if (index < 0 || index >= sc.Length)
{
int i = 0;
foreach (Screen s in sc)
{
if (s.Primary)
{
index = i;
break;
}
i++;
}
}
Screen screen = sc[index];
int x = (screen.Bounds.Width - this.Width) / 2;
int y = (screen.Bounds.Height - this.Height) / 2;
this.Location = new Point(x, y);
this.StartPosition = FormStartPosition.CenterParent;
//this.SetScreen(index);
//this.CenterToScreen();
}
}
}
}