STDEditor.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  1. using OTS.WinFormsUI.Docking;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Windows.Forms;
  7. using System.Collections;
  8. using System.Text.RegularExpressions;
  9. using OTSPartA_STDEditor.BaseClass;
  10. namespace OTSPartA_STDEditor
  11. {
  12. public partial class STDEditor : DockContent
  13. {
  14. #region 全局变量
  15. public SubMidWindow m_SubMidWindow = null;
  16. public int STDId = -1;
  17. Hashtable table_STDEditor;
  18. #endregion
  19. public enum Result
  20. {
  21. NoMatched = 0,
  22. Success = 1,
  23. Fail = 2
  24. }
  25. public STDEditor(SubMidWindow SubMidWindow)
  26. {
  27. InitializeComponent();
  28. m_SubMidWindow = SubMidWindow;
  29. X = this.Width;
  30. Y = this.Height;
  31. setTag(this);
  32. }
  33. public STDEditor(SubMidWindow SubMidWindow, string STDDBaddress)
  34. {
  35. InitializeComponent();
  36. m_SubMidWindow = SubMidWindow;
  37. X = this.Width;
  38. Y = this.Height;
  39. setTag(this);
  40. }
  41. private void STDEditor_Load(object sender, EventArgs e)
  42. {
  43. m_SubMidWindow.m_MainForm.lan = new Language(this);
  44. table_STDEditor = m_SubMidWindow.m_MainForm.lan.GetNameTable("STDEditor");
  45. comboBox_Elem1.Items.AddRange(STDInfo.Elem1);
  46. comboBox_Elem1.SelectedIndex = comboBox_Elem1.Items.IndexOf("first_elem");
  47. this.comboBox_Elem.Items.AddRange(STDInfo.Elem2);
  48. comboBox_Elem.SelectedIndex = comboBox_Elem.Items.IndexOf("Element#1");
  49. this.comboBox_ImgProperty.Items.AddRange(STDInfo.ImgProperty);
  50. comboBox_ImgProperty.SelectedIndex = comboBox_ImgProperty.Items.IndexOf("Dmax");
  51. comboBox_PeriodicTable.Items.AddRange(STDInfo.PeriodicTable);
  52. AutoCompleteStringCollection sc = new AutoCompleteStringCollection();
  53. sc.AddRange(STDInfo.PeriodicTable);
  54. this.comboBox_PeriodicTable.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
  55. this.comboBox_PeriodicTable.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
  56. this.comboBox_PeriodicTable.AutoCompleteCustomSource = sc;
  57. dataGridView_KeyElements.RowHeadersVisible = false;
  58. dataGridView_KeyElements.ColumnHeadersVisible = false;
  59. dataGridView_KeyElements.AllowUserToAddRows = false;
  60. dataGridView_KeyElements.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
  61. dataGridView_SubElements.RowHeadersVisible = false;
  62. dataGridView_SubElements.ColumnHeadersVisible = false;
  63. dataGridView_SubElements.AllowUserToAddRows = false;
  64. dataGridView_SubElements.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
  65. }
  66. /// <summary>
  67. /// [颜色:16进制转成RGB]
  68. /// </summary>
  69. /// <param name="strColor">设置16进制颜色 [返回RGB]</param>
  70. /// <returns></returns>
  71. public static System.Drawing.Color colorHx16toRGB(string strHxColor)
  72. {
  73. try
  74. {
  75. if (strHxColor.Length == 0)
  76. {//如果为空
  77. return System.Drawing.Color.FromArgb(255, 255, 204);//设为白色
  78. }
  79. else
  80. {//转换颜色
  81. return System.Drawing.Color.FromArgb(System.Int32.Parse(strHxColor.Substring(1, 2), System.Globalization.NumberStyles.AllowHexSpecifier), System.Int32.Parse(strHxColor.Substring(3, 2), System.Globalization.NumberStyles.AllowHexSpecifier), System.Int32.Parse(strHxColor.Substring(5, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
  82. }
  83. }
  84. catch
  85. {//设为白色
  86. return System.Drawing.Color.FromArgb(255, 255, 204);
  87. }
  88. }
  89. float AmplificationFactor = 1;
  90. //private void button_Extend_Click(object sender, EventArgs e)
  91. //{
  92. // if (button_Extend.BackColor == SystemColors.ControlDarkDark)
  93. // {
  94. // //groupBox_Data.Visible = true;
  95. // textbox_STDEditor.Height = (int)Math.Round(150 * AmplificationFactor);
  96. // button_Extend.BackColor = SystemColors.ControlDark;
  97. // }
  98. // else
  99. // {
  100. // button_Extend.BackColor = SystemColors.ControlDarkDark;
  101. // textbox_STDEditor.Height = (int)Math.Round(300* AmplificationFactor);
  102. // }
  103. //}
  104. private void comboBox_Elem1_SelectedIndexChanged(object sender, EventArgs e)
  105. {
  106. string newStr = comboBox_Elem1.SelectedItem.ToString();
  107. int index = textbox_STDEditor.SelectionStart;
  108. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  109. textbox_STDEditor.Focus();
  110. textbox_STDEditor.Select(index + newStr.Length, 0);
  111. textbox_STDEditor.ScrollToCaret();
  112. }
  113. private void comboBox_Elem2_SelectedIndexChanged(object sender, EventArgs e)
  114. {
  115. string newStr = comboBox_Elem.SelectedItem.ToString();
  116. int index = textbox_STDEditor.SelectionStart;
  117. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  118. textbox_STDEditor.Focus();
  119. textbox_STDEditor.Select(index + newStr.Length, 0);
  120. textbox_STDEditor.ScrollToCaret();
  121. }
  122. private void comboBox_ImgProperty_SelectedIndexChanged(object sender, EventArgs e)
  123. {
  124. string newStr = comboBox_ImgProperty.SelectedItem.ToString();
  125. int index = textbox_STDEditor.SelectionStart;
  126. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  127. textbox_STDEditor.Focus();
  128. textbox_STDEditor.Select(index + newStr.Length, 0);
  129. textbox_STDEditor.ScrollToCaret();
  130. }
  131. private void button_Plus_Click(object sender, EventArgs e)
  132. {
  133. //textbox_STDEditor 中的光标
  134. int index = textbox_STDEditor.SelectionStart;
  135. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "+");
  136. textbox_STDEditor.Focus();
  137. textbox_STDEditor.Select(index + 1, 0);
  138. textbox_STDEditor.ScrollToCaret();
  139. }
  140. private void button_Subtract_Click(object sender, EventArgs e)
  141. {
  142. //textbox_STDEditor 中的光标
  143. int index = textbox_STDEditor.SelectionStart;
  144. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "-");
  145. textbox_STDEditor.Focus();
  146. textbox_STDEditor.Select(index + 1, 0);
  147. textbox_STDEditor.ScrollToCaret();
  148. }
  149. private void button_Multiply_Click(object sender, EventArgs e)
  150. {
  151. //textbox_STDEditor 中的光标
  152. int index = textbox_STDEditor.SelectionStart;
  153. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "*");
  154. textbox_STDEditor.Focus();
  155. textbox_STDEditor.Select(index + 1, 0);
  156. textbox_STDEditor.ScrollToCaret();
  157. }
  158. private void button_Divide_Click(object sender, EventArgs e)
  159. {
  160. //textbox_STDEditor 中的光标
  161. int index = textbox_STDEditor.SelectionStart;
  162. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "/");
  163. textbox_STDEditor.Focus();
  164. textbox_STDEditor.Select(index + 1, 0);
  165. textbox_STDEditor.ScrollToCaret(); ;
  166. }
  167. private void button_More_Click(object sender, EventArgs e)
  168. {
  169. //textbox_STDEditor 中的光标
  170. int index = textbox_STDEditor.SelectionStart;
  171. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, ">");
  172. textbox_STDEditor.Focus();
  173. textbox_STDEditor.Select(index + 1, 0);
  174. textbox_STDEditor.ScrollToCaret();
  175. }
  176. private void button_Less_Click(object sender, EventArgs e)
  177. {
  178. //textbox_STDEditor 中的光标
  179. int index = textbox_STDEditor.SelectionStart;
  180. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "<");
  181. textbox_STDEditor.Focus();
  182. textbox_STDEditor.Select(index + 1, 0);
  183. textbox_STDEditor.ScrollToCaret();
  184. }
  185. private void button_LeftParenthesis_Click(object sender, EventArgs e)
  186. {
  187. //textbox_STDEditor 中的光标
  188. int index = textbox_STDEditor.SelectionStart;
  189. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "(");
  190. textbox_STDEditor.Focus();
  191. textbox_STDEditor.Select(index + 1, 0);
  192. textbox_STDEditor.ScrollToCaret();
  193. }
  194. private void button_RightParenthesis_Click(object sender, EventArgs e)
  195. {
  196. //textbox_STDEditor 中的光标
  197. int index = textbox_STDEditor.SelectionStart;
  198. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, ")");
  199. textbox_STDEditor.Focus();
  200. textbox_STDEditor.Select(index + 1, 0);
  201. textbox_STDEditor.ScrollToCaret();
  202. }
  203. private void button_Equal_Click(object sender, EventArgs e)
  204. {
  205. //textbox_STDEditor 中的光标
  206. int index = textbox_STDEditor.SelectionStart;
  207. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "=");
  208. textbox_STDEditor.Focus();
  209. textbox_STDEditor.Select(index + 1, 0);
  210. textbox_STDEditor.ScrollToCaret();
  211. }
  212. //元素下拉选择输入
  213. private void comboBox_PeriodicTable_SelectedIndexChanged(object sender, EventArgs e)
  214. {
  215. if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.SelectedItem != null)
  216. {
  217. string newStr = comboBox_PeriodicTable.SelectedItem.ToString();
  218. comboBox_PeriodicTable.Text = null;
  219. int index = textbox_STDEditor.SelectionStart;
  220. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  221. textbox_STDEditor.Focus();
  222. textbox_STDEditor.Select(index + newStr.Length, 0);
  223. textbox_STDEditor.ScrollToCaret();
  224. }
  225. }
  226. private void button_And_Click(object sender, EventArgs e)
  227. {
  228. //textbox_STDEditor 中的光标
  229. int index = textbox_STDEditor.SelectionStart;
  230. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "and");
  231. textbox_STDEditor.Focus();
  232. textbox_STDEditor.Select(index + 3, 0);
  233. textbox_STDEditor.ScrollToCaret();
  234. }
  235. private void button_Or_Click(object sender, EventArgs e)
  236. {
  237. //textbox_STDEditor 中的光标
  238. int index = textbox_STDEditor.SelectionStart;
  239. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "or");
  240. textbox_STDEditor.Focus();
  241. textbox_STDEditor.Select(index + 2, 0);
  242. textbox_STDEditor.ScrollToCaret();
  243. }
  244. private void comboBox_Constants_SelectedIndexChanged(object sender, EventArgs e)
  245. {
  246. if (comboBox_Constants.SelectedItem != null)
  247. {
  248. string newStr = comboBox_Constants.SelectedItem.ToString().Split('=')[0];
  249. int index = textbox_STDEditor.SelectionStart;
  250. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  251. textbox_STDEditor.Focus();
  252. textbox_STDEditor.Select(index + newStr.Length, 0);
  253. textbox_STDEditor.ScrollToCaret();
  254. }
  255. }
  256. private void button_1_Click(object sender, EventArgs e)
  257. {
  258. //textbox_STDEditor 中的光标
  259. int index = textbox_STDEditor.SelectionStart;
  260. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "1");
  261. textbox_STDEditor.Focus();
  262. textbox_STDEditor.Select(index + 1, 0);
  263. textbox_STDEditor.ScrollToCaret();
  264. }
  265. private void button_2_Click(object sender, EventArgs e)
  266. {
  267. //textbox_STDEditor 中的光标
  268. int index = textbox_STDEditor.SelectionStart;
  269. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "2");
  270. textbox_STDEditor.Focus();
  271. textbox_STDEditor.Select(index + 1, 0);
  272. textbox_STDEditor.ScrollToCaret();
  273. }
  274. private void button_3_Click(object sender, EventArgs e)
  275. {
  276. //textbox_STDEditor 中的光标
  277. int index = textbox_STDEditor.SelectionStart;
  278. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "3");
  279. textbox_STDEditor.Focus();
  280. textbox_STDEditor.Select(index + 1, 0);
  281. textbox_STDEditor.ScrollToCaret();
  282. }
  283. private void button_4_Click(object sender, EventArgs e)
  284. {
  285. //textbox_STDEditor 中的光标
  286. int index = textbox_STDEditor.SelectionStart;
  287. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "4");
  288. textbox_STDEditor.Focus();
  289. textbox_STDEditor.Select(index + 1, 0);
  290. textbox_STDEditor.ScrollToCaret();
  291. }
  292. private void button_5_Click(object sender, EventArgs e)
  293. {
  294. //textbox_STDEditor 中的光标
  295. int index = textbox_STDEditor.SelectionStart;
  296. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "5");
  297. textbox_STDEditor.Focus();
  298. textbox_STDEditor.Select(index + 1, 0);
  299. textbox_STDEditor.ScrollToCaret();
  300. }
  301. private void button_6_Click(object sender, EventArgs e)
  302. {
  303. //textbox_STDEditor 中的光标
  304. int index = textbox_STDEditor.SelectionStart;
  305. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "6");
  306. textbox_STDEditor.Focus();
  307. textbox_STDEditor.Select(index + 1, 0);
  308. textbox_STDEditor.ScrollToCaret();
  309. }
  310. private void button_7_Click(object sender, EventArgs e)
  311. {
  312. //textbox_STDEditor 中的光标
  313. int index = textbox_STDEditor.SelectionStart;
  314. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "7");
  315. textbox_STDEditor.Focus();
  316. textbox_STDEditor.Select(index + 1, 0);
  317. textbox_STDEditor.ScrollToCaret();
  318. }
  319. private void button_8_Click(object sender, EventArgs e)
  320. {
  321. //textbox_STDEditor 中的光标
  322. int index = textbox_STDEditor.SelectionStart;
  323. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "8");
  324. textbox_STDEditor.Focus();
  325. textbox_STDEditor.Select(index + 1, 0);
  326. textbox_STDEditor.ScrollToCaret();
  327. }
  328. private void button_9_Click(object sender, EventArgs e)
  329. {
  330. //textbox_STDEditor 中的光标
  331. int index = textbox_STDEditor.SelectionStart;
  332. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "9");
  333. textbox_STDEditor.Focus();
  334. textbox_STDEditor.Select(index + 1, 0);
  335. textbox_STDEditor.ScrollToCaret();
  336. }
  337. private void button_0_Click(object sender, EventArgs e)
  338. {
  339. int index = textbox_STDEditor.SelectionStart;
  340. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "0");
  341. textbox_STDEditor.Focus();
  342. textbox_STDEditor.Select(index + 1, 0);
  343. textbox_STDEditor.ScrollToCaret();
  344. }
  345. //元素自身text按回车键输入
  346. private void comboBox_PeriodicTable_KeyDown(object sender, KeyEventArgs e)
  347. {
  348. if (e.KeyValue == 13)
  349. {
  350. if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.Text != "")
  351. {
  352. this.textbox_STDEditor.Text += comboBox_PeriodicTable.Text.ToString();
  353. comboBox_PeriodicTable.Text = null;
  354. }
  355. }
  356. }
  357. /// <summary>
  358. /// 将颜色对象转换为uint
  359. /// </summary>
  360. /// <param name="color"></param>
  361. /// <returns></returns>
  362. public uint ParseRGB(Color color)
  363. {
  364. return (uint)(((uint)color.B << 16) | (ushort)(((ushort)color.G << 8) | color.R));
  365. }
  366. #region 常用数据验证的封装,数字字符的验证
  367. /// <summary>
  368. /// 常用数据验证的封装,数字字符的验证
  369. /// </summary>
  370. /// <param name="inputVal">需要验证的数值【字符串,或者数字】</param>
  371. /// <param name="type">类型为哪一个验证</param>
  372. /// <returns>如果验证成功则返回True,否则返回false</returns>
  373. public bool IsMatch(string inputVal, int type)
  374. {
  375. switch (type)
  376. {
  377. case 0:
  378. return Regex.IsMatch(inputVal, @"^[1-9]d*$"); //匹配正整数
  379. case 1:
  380. return Regex.IsMatch(inputVal, @"^-?\d+$"); //匹配整数
  381. case 2:
  382. return Regex.IsMatch(inputVal, @"^[A-Za-z0-9]+$"); //匹配由数字和26个英文字母组成的字符串
  383. case 3:
  384. return Regex.IsMatch(inputVal, @"^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$"); //匹配正浮点数
  385. case 4:
  386. return Regex.IsMatch(inputVal, @"^[\u4e00-\u9fa5]{0,}$"); //匹配汉字
  387. case 5:
  388. return Regex.IsMatch(inputVal, @"^[0-9]+(.[0-9]{1,3})?$"); //匹配1~3位小数的正实数
  389. case 6:
  390. return Regex.IsMatch(inputVal, @"^[A-Za-z]+$"); //匹配英文字符
  391. default:
  392. return true;
  393. }
  394. }
  395. #endregion
  396. #region 弹出提示
  397. /// <summary>
  398. /// 弹出提示
  399. /// </summary>
  400. /// <param name="strContent"></param>
  401. protected void showMessage(string strContent)
  402. {
  403. MessageBox.Show(strContent, "Tip");
  404. }
  405. #endregion
  406. #region 控制BSE、化学式、元素本文框中不能输入下划线
  407. /// <summary>
  408. /// 控件不能输入下划线
  409. /// </summary>
  410. /// <param name="sender"></param>
  411. /// <param name="e"></param>
  412. private void textBox_KeyPress(object sender, KeyPressEventArgs e)
  413. {
  414. if ((e.KeyChar >= '0' && e.KeyChar <= '9') || (e.KeyChar >= 'A' && e.KeyChar <= 'Z') ||
  415. (e.KeyChar >= 'a' && e.KeyChar <= 'z') || (e.KeyChar == 8) || !(e.KeyChar == '_'))
  416. {
  417. e.Handled = false;
  418. }
  419. else
  420. {
  421. e.Handled = true;
  422. }
  423. }
  424. #endregion
  425. string ElementKeyOrSub = "";
  426. private void dataGridView_KeyElements_CellClick(object sender, DataGridViewCellEventArgs e)
  427. {
  428. ElementKeyOrSub = dataGridView_KeyElements.CurrentCell.Value.ToString();
  429. dataGridView_KeyElements.Columns.RemoveAt(e.ColumnIndex);
  430. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  431. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  432. dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  433. if (dataGridView_SubElements.Rows.Count == 0)
  434. {
  435. DataGridViewRow row = new DataGridViewRow();
  436. dataGridView_SubElements.Rows.Add(row);
  437. }
  438. dataGridView_SubElements.Rows[0].Cells[dataGridView_SubElements.Columns.Count - 1].Value = ElementKeyOrSub;
  439. dataGridView_SubElements.ClearSelection();
  440. dataGridView_KeyElements.ClearSelection();
  441. }
  442. private void dataGridView_SubElements_CellClick(object sender, DataGridViewCellEventArgs e)
  443. {
  444. ElementKeyOrSub = dataGridView_SubElements.CurrentCell.Value.ToString();
  445. dataGridView_SubElements.Columns.RemoveAt(e.ColumnIndex);
  446. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  447. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  448. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  449. if (dataGridView_KeyElements.Rows.Count == 0)
  450. {
  451. DataGridViewRow row = new DataGridViewRow();
  452. dataGridView_KeyElements.Rows.Add(row);
  453. }
  454. dataGridView_KeyElements.Rows[0].Cells[dataGridView_KeyElements.Columns.Count - 1].Value = ElementKeyOrSub;
  455. dataGridView_KeyElements.ClearSelection();
  456. dataGridView_SubElements.ClearSelection();
  457. }
  458. private float X = 1;
  459. private float Y = 1;
  460. private void STDEditor_Resize(object sender, EventArgs e)
  461. {
  462. float newx = (this.Width) / X;
  463. float newy = this.Height / Y;
  464. AmplificationFactor = newy;
  465. setControls(newx, newy, this.tabSTDStandrad.TabPages[0]);
  466. //button_Extend.BackColor = SystemColors.ControlDarkDark;
  467. }
  468. private void setTag(Control cons)
  469. {
  470. foreach (Control con in cons.Controls)
  471. {
  472. con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;
  473. if (con.Controls.Count > 0)
  474. setTag(con);
  475. }
  476. }
  477. private void setControls(float newx, float newy, Control cons)
  478. {
  479. foreach (Control con in cons.Controls)
  480. {
  481. if (false)
  482. {
  483. }
  484. else
  485. {
  486. string[] mytag = con.Tag.ToString().Split(':');
  487. float a = Convert.ToSingle(mytag[0]) * newx;
  488. con.Width = (int)a;
  489. a = Convert.ToSingle(mytag[1]) * newy;
  490. con.Height = (int)(a);
  491. a = Convert.ToSingle(mytag[2]) * newx;
  492. con.Left = (int)(a);
  493. a = Convert.ToSingle(mytag[3]) * newy;
  494. con.Top = (int)(a);
  495. Single currentSize;
  496. if (con.Name == "button_Extend")
  497. {
  498. currentSize = 6f;
  499. }
  500. else
  501. {
  502. if (Math.Max(newx, newy) < 1)
  503. {
  504. currentSize = Convert.ToSingle(mytag[4]) * 1;
  505. }
  506. else
  507. {
  508. currentSize = Convert.ToSingle(mytag[4]) * Math.Max(newx, newy);
  509. }
  510. }
  511. con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
  512. if (con.Controls.Count > 0)
  513. {
  514. setControls(newx, newy, con);
  515. }
  516. }
  517. }
  518. }
  519. Form_PeriodicTable form_PeriodicTable;
  520. private void button_PeriodicTableSwitch_Click(object sender, EventArgs e)
  521. {
  522. if (form_PeriodicTable == null) //如果子窗体为空则创造实例 并显示
  523. {
  524. form_PeriodicTable = new Form_PeriodicTable();
  525. if (table_STDEditor["language"].ToString() == "EN")
  526. {
  527. form_PeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_EN;
  528. }
  529. else
  530. {
  531. form_PeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_ZH;
  532. }
  533. form_PeriodicTable.Show();
  534. }
  535. else
  536. {
  537. if (form_PeriodicTable.IsDisposed) //若子窗体关闭 则打开新子窗体 并显示
  538. {
  539. form_PeriodicTable = new Form_PeriodicTable();
  540. if (table_STDEditor["language"].ToString() == "EN")
  541. {
  542. form_PeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_EN;
  543. }
  544. else
  545. {
  546. form_PeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_ZH;
  547. }
  548. form_PeriodicTable.Show();
  549. }
  550. else
  551. {
  552. form_PeriodicTable.Activate(); //使子窗体获得焦点
  553. }
  554. }
  555. }
  556. private void textbox_STDEditor_MouseLeave(object sender, EventArgs e)
  557. {
  558. dataGridView_SubElements.Rows.Clear();
  559. dataGridView_SubElements.Columns.Clear();
  560. string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
  561. str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
  562. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  563. List<string> str_Removeandor = new List<string>();
  564. for (int i = 0; i < str_Removeand.Length; i++)
  565. {
  566. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  567. }
  568. List<string> list_all = new List<string>();
  569. for (int i = 0; i < str_Removeandor.Count; i++)
  570. {
  571. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  572. }
  573. List<string> UsingElementL = new List<string>();
  574. for (int i = 0; i < list_all.Count; i++)
  575. {
  576. if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  577. {
  578. if (!UsingElementL.Contains(list_all[i]))
  579. {
  580. UsingElementL.Add(list_all[i]);
  581. }
  582. }
  583. }
  584. List<string> KeyElements = new List<string>();
  585. for (int i = 0; i < dataGridView_KeyElements.ColumnCount; i++)
  586. {
  587. if (UsingElementL.Contains(dataGridView_KeyElements.Rows[0].Cells[i].Value))
  588. {
  589. KeyElements.Add(dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString());
  590. }
  591. }
  592. dataGridView_KeyElements.Rows.Clear();
  593. dataGridView_KeyElements.Columns.Clear();
  594. for (int i = 0; i < KeyElements.Count; i++)
  595. {
  596. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  597. dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
  598. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  599. if (dataGridView_KeyElements.Rows.Count == 0)
  600. {
  601. DataGridViewRow row = new DataGridViewRow();
  602. dataGridView_KeyElements.Rows.Add(row);
  603. }
  604. dataGridView_KeyElements.Rows[0].Cells[dataGridView_KeyElements.ColumnCount - 1].Value = KeyElements[i];
  605. }
  606. if (KeyElements.Count > 0)
  607. {
  608. for (int i = 0; i < UsingElementL.Count; i++)
  609. {
  610. if (!KeyElements.Contains(UsingElementL[i]))
  611. {
  612. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  613. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  614. dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  615. if (dataGridView_SubElements.Rows.Count == 0)
  616. {
  617. DataGridViewRow row = new DataGridViewRow();
  618. dataGridView_SubElements.Rows.Add(row);
  619. }
  620. dataGridView_SubElements.Rows[0].Cells[dataGridView_SubElements.ColumnCount - 1].Value = UsingElementL[i];
  621. }
  622. }
  623. }
  624. else
  625. {
  626. for (int i = 0; i < UsingElementL.Count; i++)
  627. {
  628. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  629. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  630. dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  631. if (dataGridView_SubElements.Rows.Count == 0)
  632. {
  633. DataGridViewRow row = new DataGridViewRow();
  634. dataGridView_SubElements.Rows.Add(row);
  635. }
  636. dataGridView_SubElements.Rows[0].Cells[i].Value = UsingElementL[i];
  637. }
  638. }
  639. dataGridView_KeyElements.ClearSelection();
  640. dataGridView_SubElements.ClearSelection();
  641. }
  642. private void button_del_Click(object sender, EventArgs e)
  643. {
  644. if (!string.IsNullOrEmpty(textbox_STDEditor.Text))
  645. {
  646. if (textbox_STDEditor.SelectionLength == 0)
  647. {
  648. textbox_STDEditor.Text = textbox_STDEditor.Text.Remove(textbox_STDEditor.SelectionStart - 1, 1);
  649. }
  650. else
  651. {
  652. textbox_STDEditor.Text = textbox_STDEditor.Text.Remove(textbox_STDEditor.SelectionStart, textbox_STDEditor.SelectionLength);
  653. }
  654. }
  655. textbox_STDEditor.Focus();
  656. textbox_STDEditor.SelectionStart = textbox_STDEditor.Text.Length;
  657. }
  658. private void label_help2_MouseHover(object sender, EventArgs e)
  659. {
  660. // 创建the ToolTip
  661. ToolTip toolTip1 = new ToolTip();
  662. // 设置显示样式
  663. toolTip1.AutoPopDelay = 7000;//提示信息的可见时间
  664. toolTip1.InitialDelay = 500;//事件触发多久后出现提示
  665. toolTip1.ReshowDelay = 500;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  666. toolTip1.ShowAlways = true;//是否显示提示框
  667. string str = "Dmax:颗粒最大卡规直径\n"+
  668. "Dmin: 颗粒最小卡规直径\n" +
  669. "Aspect:颗粒长宽比\n" +
  670. "Dperp:与Dmax垂直的对应直径\n"+
  671. "Dmean:平均内接圆直径\n"+
  672. "Area:面积\n"+
  673. "Dferet:费雷特直径\n"+
  674. "Width:宽度(直上直下那种)\n"+
  675. "Height:高度(直上直下那种)\n"+
  676. "Perimeter:周长\n"+
  677. "Dinscr:最大内接圆直径\n"+
  678. "Orientation:朝向角度\n"+
  679. "Delong:展开长度(以最小卡规直径为宽)\n" +
  680. "Aspectelong:展开后长宽比\n"+
  681. "Dequalcircle:等效圆直径\n"+
  682. "Vedio:BSE灰度平均值";
  683. // 设置伴随的对象.
  684. toolTip1.SetToolTip(this.label_help2, str);
  685. }
  686. private void label_help1label2_MouseHover(object sender, EventArgs e)
  687. {
  688. // 创建the ToolTip
  689. ToolTip toolTip1 = new ToolTip();
  690. // 设置显示样式
  691. toolTip1.AutoPopDelay = 7000;//提示信息的可见时间
  692. toolTip1.InitialDelay = 500;//事件触发多久后出现提示
  693. toolTip1.ReshowDelay = 500;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  694. toolTip1.ShowAlways = true;//是否显示提示框
  695. string str = "first_elem/Element#1:颗粒元素分析结果中最大占比的元素";
  696. // 设置伴随的对象.
  697. toolTip1.SetToolTip(this.label_help1, str);
  698. }
  699. }
  700. }