ImageIndexDialog.cs 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095
  1. using PaintDotNet.Actions;
  2. using PaintDotNet.Annotation;
  3. using PaintDotNet.Annotation.Enum;
  4. using PaintDotNet.Annotation.Label;
  5. using PaintDotNet.Base;
  6. using PaintDotNet.Base.CommTool;
  7. using PaintDotNet.Base.SettingModel;
  8. using PaintDotNet.File;
  9. using PaintDotNet.Setting;
  10. using System;
  11. using System.Collections;
  12. using System.Collections.Generic;
  13. using System.Drawing;
  14. using System.IO;
  15. using System.Linq;
  16. using System.Reflection;
  17. using System.Windows.Forms;
  18. using static PaintDotNet.Base.SettingModel.CustomTxtModel;
  19. namespace PaintDotNet.Instrument
  20. {
  21. /// <summary>
  22. /// 图像索引
  23. /// </summary>
  24. internal class ImageIndexDialog : FloatingToolForm
  25. {
  26. public static ImageIndexDialog imageIndexDialog;
  27. private PictureBox pictureBox1;
  28. private Panel panel1;
  29. public Label lblPreview;
  30. #region 控件
  31. /// <summary>
  32. /// Required designer variable.
  33. /// </summary>
  34. private System.ComponentModel.IContainer components = null;
  35. /// <summary>
  36. /// Clean up any resources being used.
  37. /// </summary>
  38. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  39. protected override void Dispose(bool disposing)
  40. {
  41. if (disposing && (components != null))
  42. {
  43. components.Dispose();
  44. }
  45. base.Dispose(disposing);
  46. }
  47. #region Windows Form Designer generated code
  48. /// <summary>
  49. /// Required method for Designer support - do not modify
  50. /// the contents of this method with the code editor.
  51. /// </summary>
  52. private void InitializeComponent()
  53. {
  54. this.components = new System.ComponentModel.Container();
  55. this.groupBox1 = new System.Windows.Forms.GroupBox();
  56. this.button10 = new System.Windows.Forms.Button();
  57. this.btn_Hide = new System.Windows.Forms.Button();
  58. this.listView1 = new System.Windows.Forms.ListView();
  59. this.imageList1 = new System.Windows.Forms.ImageList(this.components);
  60. this.button7 = new System.Windows.Forms.Button();
  61. this.button8 = new System.Windows.Forms.Button();
  62. this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
  63. this.groupBox2 = new System.Windows.Forms.GroupBox();
  64. this.lblPreview = new System.Windows.Forms.Label();
  65. this.btn_DelT3 = new System.Windows.Forms.Button();
  66. this.btn_DelT2 = new System.Windows.Forms.Button();
  67. this.btn_DelT1 = new System.Windows.Forms.Button();
  68. this.btn_AddT3 = new System.Windows.Forms.Button();
  69. this.btn_AddT2 = new System.Windows.Forms.Button();
  70. this.btn_AddT1 = new System.Windows.Forms.Button();
  71. this.label3 = new System.Windows.Forms.Label();
  72. this.label2 = new System.Windows.Forms.Label();
  73. this.label1 = new System.Windows.Forms.Label();
  74. this.comboBox_T3 = new System.Windows.Forms.ComboBox();
  75. this.comboBox_T2 = new System.Windows.Forms.ComboBox();
  76. this.comboBox_T1 = new System.Windows.Forms.ComboBox();
  77. this.btn_SetUp = new System.Windows.Forms.Button();
  78. this.comboBox_Name = new System.Windows.Forms.ComboBox();
  79. this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
  80. this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
  81. this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem();
  82. this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem();
  83. this.toolStripMenuItem4 = new System.Windows.Forms.ToolStripMenuItem();
  84. this.splitContainer1 = new System.Windows.Forms.SplitContainer();
  85. this.pictureBox1 = new System.Windows.Forms.PictureBox();
  86. this.panel1 = new System.Windows.Forms.Panel();
  87. this.groupBox1.SuspendLayout();
  88. this.groupBox2.SuspendLayout();
  89. this.contextMenuStrip1.SuspendLayout();
  90. ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
  91. this.splitContainer1.Panel1.SuspendLayout();
  92. this.splitContainer1.Panel2.SuspendLayout();
  93. this.splitContainer1.SuspendLayout();
  94. ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
  95. this.panel1.SuspendLayout();
  96. this.SuspendLayout();
  97. //
  98. // groupBox1
  99. //
  100. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  101. | System.Windows.Forms.AnchorStyles.Left)
  102. | System.Windows.Forms.AnchorStyles.Right)));
  103. this.groupBox1.Controls.Add(this.button10);
  104. this.groupBox1.Controls.Add(this.btn_Hide);
  105. this.groupBox1.Controls.Add(this.listView1);
  106. this.groupBox1.Controls.Add(this.button7);
  107. this.groupBox1.Controls.Add(this.button8);
  108. this.groupBox1.Location = new System.Drawing.Point(5, 160);
  109. this.groupBox1.Name = "groupBox1";
  110. this.groupBox1.Size = new System.Drawing.Size(178, 367);
  111. this.groupBox1.TabIndex = 1;
  112. this.groupBox1.TabStop = false;
  113. this.groupBox1.Text = "索引列表";
  114. //
  115. // button10
  116. //
  117. this.button10.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  118. this.button10.Location = new System.Drawing.Point(116, 338);
  119. this.button10.Name = "button10";
  120. this.button10.Size = new System.Drawing.Size(25, 25);
  121. this.button10.TabIndex = 19;
  122. this.button10.UseVisualStyleBackColor = true;
  123. this.button10.Click += new System.EventHandler(this.button10_Click);
  124. //
  125. // btn_Hide
  126. //
  127. this.btn_Hide.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  128. this.btn_Hide.Location = new System.Drawing.Point(147, 338);
  129. this.btn_Hide.Name = "btn_Hide";
  130. this.btn_Hide.Size = new System.Drawing.Size(25, 25);
  131. this.btn_Hide.TabIndex = 18;
  132. this.btn_Hide.Text = ">>";
  133. this.btn_Hide.UseVisualStyleBackColor = true;
  134. this.btn_Hide.Click += new System.EventHandler(this.btn_Hide_Click);
  135. //
  136. // listView1
  137. //
  138. this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  139. | System.Windows.Forms.AnchorStyles.Left)
  140. | System.Windows.Forms.AnchorStyles.Right)));
  141. this.listView1.HideSelection = false;
  142. this.listView1.LargeImageList = this.imageList1;
  143. this.listView1.Location = new System.Drawing.Point(7, 20);
  144. this.listView1.MultiSelect = false;
  145. this.listView1.Name = "listView1";
  146. this.listView1.ShowItemToolTips = true;
  147. this.listView1.Size = new System.Drawing.Size(165, 316);
  148. this.listView1.TabIndex = 0;
  149. this.listView1.UseCompatibleStateImageBehavior = false;
  150. this.listView1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseClick);
  151. this.listView1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseDoubleClick);
  152. //
  153. // imageList1
  154. //
  155. this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
  156. this.imageList1.ImageSize = new System.Drawing.Size(256, 256);
  157. this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
  158. //
  159. // button7
  160. //
  161. this.button7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  162. this.button7.Location = new System.Drawing.Point(54, 338);
  163. this.button7.Name = "button7";
  164. this.button7.Size = new System.Drawing.Size(25, 25);
  165. this.button7.TabIndex = 16;
  166. this.button7.UseVisualStyleBackColor = true;
  167. this.button7.Click += new System.EventHandler(this.button7_Click);
  168. //
  169. // button8
  170. //
  171. this.button8.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  172. this.button8.Location = new System.Drawing.Point(85, 338);
  173. this.button8.Name = "button8";
  174. this.button8.Size = new System.Drawing.Size(25, 25);
  175. this.button8.TabIndex = 15;
  176. this.button8.UseVisualStyleBackColor = true;
  177. this.button8.Click += new System.EventHandler(this.button8_Click);
  178. //
  179. // groupBox2
  180. //
  181. this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  182. | System.Windows.Forms.AnchorStyles.Right)));
  183. this.groupBox2.Controls.Add(this.lblPreview);
  184. this.groupBox2.Controls.Add(this.btn_DelT3);
  185. this.groupBox2.Controls.Add(this.btn_DelT2);
  186. this.groupBox2.Controls.Add(this.btn_DelT1);
  187. this.groupBox2.Controls.Add(this.btn_AddT3);
  188. this.groupBox2.Controls.Add(this.btn_AddT2);
  189. this.groupBox2.Controls.Add(this.btn_AddT1);
  190. this.groupBox2.Controls.Add(this.label3);
  191. this.groupBox2.Controls.Add(this.label2);
  192. this.groupBox2.Controls.Add(this.label1);
  193. this.groupBox2.Controls.Add(this.comboBox_T3);
  194. this.groupBox2.Controls.Add(this.comboBox_T2);
  195. this.groupBox2.Controls.Add(this.comboBox_T1);
  196. this.groupBox2.Controls.Add(this.btn_SetUp);
  197. this.groupBox2.Controls.Add(this.comboBox_Name);
  198. this.groupBox2.Location = new System.Drawing.Point(5, 5);
  199. this.groupBox2.MaximumSize = new System.Drawing.Size(366, 149);
  200. this.groupBox2.Name = "groupBox2";
  201. this.groupBox2.Size = new System.Drawing.Size(178, 149);
  202. this.groupBox2.TabIndex = 25;
  203. this.groupBox2.TabStop = false;
  204. this.groupBox2.Text = "命名规则";
  205. //
  206. // lblPreview
  207. //
  208. this.lblPreview.AutoEllipsis = true;
  209. this.lblPreview.ForeColor = System.Drawing.SystemColors.ControlDarkDark;
  210. this.lblPreview.Location = new System.Drawing.Point(6, 44);
  211. this.lblPreview.Name = "lblPreview";
  212. this.lblPreview.Size = new System.Drawing.Size(166, 12);
  213. this.lblPreview.TabIndex = 29;
  214. this.lblPreview.Text = "lblPreview";
  215. //
  216. // btn_DelT3
  217. //
  218. this.btn_DelT3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  219. this.btn_DelT3.Location = new System.Drawing.Point(147, 118);
  220. this.btn_DelT3.Name = "btn_DelT3";
  221. this.btn_DelT3.Size = new System.Drawing.Size(25, 25);
  222. this.btn_DelT3.TabIndex = 28;
  223. this.btn_DelT3.Text = "-";
  224. this.btn_DelT3.UseVisualStyleBackColor = true;
  225. this.btn_DelT3.Click += new System.EventHandler(this.btn_DelT3_Click);
  226. //
  227. // btn_DelT2
  228. //
  229. this.btn_DelT2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  230. this.btn_DelT2.Location = new System.Drawing.Point(147, 93);
  231. this.btn_DelT2.Name = "btn_DelT2";
  232. this.btn_DelT2.Size = new System.Drawing.Size(25, 25);
  233. this.btn_DelT2.TabIndex = 27;
  234. this.btn_DelT2.Text = "-";
  235. this.btn_DelT2.UseVisualStyleBackColor = true;
  236. this.btn_DelT2.Click += new System.EventHandler(this.btn_DelT2_Click);
  237. //
  238. // btn_DelT1
  239. //
  240. this.btn_DelT1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  241. this.btn_DelT1.Location = new System.Drawing.Point(147, 68);
  242. this.btn_DelT1.Name = "btn_DelT1";
  243. this.btn_DelT1.Size = new System.Drawing.Size(25, 25);
  244. this.btn_DelT1.TabIndex = 26;
  245. this.btn_DelT1.Text = "-";
  246. this.btn_DelT1.UseVisualStyleBackColor = true;
  247. this.btn_DelT1.Click += new System.EventHandler(this.btn_DelT1_Click);
  248. //
  249. // btn_AddT3
  250. //
  251. this.btn_AddT3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  252. this.btn_AddT3.Location = new System.Drawing.Point(123, 118);
  253. this.btn_AddT3.Name = "btn_AddT3";
  254. this.btn_AddT3.Size = new System.Drawing.Size(25, 25);
  255. this.btn_AddT3.TabIndex = 25;
  256. this.btn_AddT3.Text = "+";
  257. this.btn_AddT3.UseVisualStyleBackColor = true;
  258. this.btn_AddT3.Click += new System.EventHandler(this.btn_AddT3_Click);
  259. //
  260. // btn_AddT2
  261. //
  262. this.btn_AddT2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  263. this.btn_AddT2.Location = new System.Drawing.Point(123, 93);
  264. this.btn_AddT2.Name = "btn_AddT2";
  265. this.btn_AddT2.Size = new System.Drawing.Size(25, 25);
  266. this.btn_AddT2.TabIndex = 24;
  267. this.btn_AddT2.Text = "+";
  268. this.btn_AddT2.UseVisualStyleBackColor = true;
  269. this.btn_AddT2.Click += new System.EventHandler(this.btn_AddT2_Click);
  270. //
  271. // btn_AddT1
  272. //
  273. this.btn_AddT1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  274. this.btn_AddT1.Location = new System.Drawing.Point(123, 68);
  275. this.btn_AddT1.Name = "btn_AddT1";
  276. this.btn_AddT1.Size = new System.Drawing.Size(25, 25);
  277. this.btn_AddT1.TabIndex = 23;
  278. this.btn_AddT1.Text = "+";
  279. this.btn_AddT1.UseVisualStyleBackColor = true;
  280. this.btn_AddT1.Click += new System.EventHandler(this.btn_AddT1_Click);
  281. //
  282. // label3
  283. //
  284. this.label3.AutoSize = true;
  285. this.label3.Location = new System.Drawing.Point(6, 123);
  286. this.label3.Name = "label3";
  287. this.label3.Size = new System.Drawing.Size(23, 12);
  288. this.label3.TabIndex = 22;
  289. this.label3.Text = "T3:";
  290. //
  291. // label2
  292. //
  293. this.label2.AutoSize = true;
  294. this.label2.Location = new System.Drawing.Point(6, 99);
  295. this.label2.Name = "label2";
  296. this.label2.Size = new System.Drawing.Size(23, 12);
  297. this.label2.TabIndex = 21;
  298. this.label2.Text = "T2:";
  299. //
  300. // label1
  301. //
  302. this.label1.AutoSize = true;
  303. this.label1.Location = new System.Drawing.Point(6, 74);
  304. this.label1.Name = "label1";
  305. this.label1.Size = new System.Drawing.Size(23, 12);
  306. this.label1.TabIndex = 20;
  307. this.label1.Text = "T1:";
  308. //
  309. // comboBox_T3
  310. //
  311. this.comboBox_T3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
  312. this.comboBox_T3.FormattingEnabled = true;
  313. this.comboBox_T3.Location = new System.Drawing.Point(35, 120);
  314. this.comboBox_T3.Name = "comboBox_T3";
  315. this.comboBox_T3.Size = new System.Drawing.Size(82, 20);
  316. this.comboBox_T3.TabIndex = 19;
  317. this.comboBox_T3.TextUpdate += new System.EventHandler(this.comboBox_T3_TextUpdate);
  318. //
  319. // comboBox_T2
  320. //
  321. this.comboBox_T2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
  322. this.comboBox_T2.FormattingEnabled = true;
  323. this.comboBox_T2.Location = new System.Drawing.Point(35, 96);
  324. this.comboBox_T2.Name = "comboBox_T2";
  325. this.comboBox_T2.Size = new System.Drawing.Size(82, 20);
  326. this.comboBox_T2.TabIndex = 18;
  327. this.comboBox_T2.TextUpdate += new System.EventHandler(this.comboBox_T2_TextUpdate);
  328. //
  329. // comboBox_T1
  330. //
  331. this.comboBox_T1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
  332. this.comboBox_T1.FormattingEnabled = true;
  333. this.comboBox_T1.Location = new System.Drawing.Point(35, 71);
  334. this.comboBox_T1.Name = "comboBox_T1";
  335. this.comboBox_T1.Size = new System.Drawing.Size(82, 20);
  336. this.comboBox_T1.TabIndex = 17;
  337. this.comboBox_T1.TextUpdate += new System.EventHandler(this.comboBox_T1_TextUpdate);
  338. //
  339. // btn_SetUp
  340. //
  341. this.btn_SetUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  342. this.btn_SetUp.Location = new System.Drawing.Point(147, 16);
  343. this.btn_SetUp.Name = "btn_SetUp";
  344. this.btn_SetUp.Size = new System.Drawing.Size(25, 25);
  345. this.btn_SetUp.TabIndex = 16;
  346. this.btn_SetUp.Text = "*";
  347. this.btn_SetUp.UseVisualStyleBackColor = true;
  348. this.btn_SetUp.Click += new System.EventHandler(this.btn_SetUp_Click);
  349. //
  350. // comboBox_Name
  351. //
  352. this.comboBox_Name.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
  353. this.comboBox_Name.FormattingEnabled = true;
  354. this.comboBox_Name.Location = new System.Drawing.Point(7, 18);
  355. this.comboBox_Name.Name = "comboBox_Name";
  356. this.comboBox_Name.Size = new System.Drawing.Size(128, 20);
  357. this.comboBox_Name.TabIndex = 0;
  358. //
  359. // contextMenuStrip1
  360. //
  361. this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
  362. this.toolStripMenuItem1,
  363. this.toolStripMenuItem2,
  364. this.toolStripMenuItem3,
  365. this.toolStripMenuItem4});
  366. this.contextMenuStrip1.Name = "contextMenuStrip1";
  367. this.contextMenuStrip1.Size = new System.Drawing.Size(125, 92);
  368. //
  369. // toolStripMenuItem1
  370. //
  371. this.toolStripMenuItem1.Name = "toolStripMenuItem1";
  372. this.toolStripMenuItem1.Size = new System.Drawing.Size(124, 22);
  373. this.toolStripMenuItem1.Text = "保存";
  374. this.toolStripMenuItem1.Click += new System.EventHandler(this.toolStripMenuItem1_Click);
  375. //
  376. // toolStripMenuItem2
  377. //
  378. this.toolStripMenuItem2.Name = "toolStripMenuItem2";
  379. this.toolStripMenuItem2.Size = new System.Drawing.Size(124, 22);
  380. this.toolStripMenuItem2.Text = "另存";
  381. this.toolStripMenuItem2.Click += new System.EventHandler(this.toolStripMenuItem2_Click);
  382. //
  383. // toolStripMenuItem3
  384. //
  385. this.toolStripMenuItem3.Name = "toolStripMenuItem3";
  386. this.toolStripMenuItem3.Size = new System.Drawing.Size(124, 22);
  387. this.toolStripMenuItem3.Text = "强制关闭";
  388. this.toolStripMenuItem3.Click += new System.EventHandler(this.toolStripMenuItem3_Click);
  389. //
  390. // toolStripMenuItem4
  391. //
  392. this.toolStripMenuItem4.Name = "toolStripMenuItem4";
  393. this.toolStripMenuItem4.Size = new System.Drawing.Size(124, 22);
  394. this.toolStripMenuItem4.Text = "复制";
  395. this.toolStripMenuItem4.Click += new System.EventHandler(this.toolStripMenuItem4_Click);
  396. //
  397. // splitContainer1
  398. //
  399. this.splitContainer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  400. this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
  401. this.splitContainer1.Location = new System.Drawing.Point(0, 0);
  402. this.splitContainer1.Name = "splitContainer1";
  403. //
  404. // splitContainer1.Panel1
  405. //
  406. this.splitContainer1.Panel1.Controls.Add(this.groupBox2);
  407. this.splitContainer1.Panel1.Controls.Add(this.groupBox1);
  408. this.splitContainer1.Panel1.SizeChanged += new System.EventHandler(this.splitContainer1_Panel1_SizeChanged);
  409. this.splitContainer1.Panel1MinSize = 188;
  410. //
  411. // splitContainer1.Panel2
  412. //
  413. this.splitContainer1.Panel2.Controls.Add(this.pictureBox1);
  414. this.splitContainer1.Panel2MinSize = 0;
  415. this.splitContainer1.Size = new System.Drawing.Size(810, 532);
  416. this.splitContainer1.SplitterDistance = 188;
  417. this.splitContainer1.TabIndex = 26;
  418. //
  419. // pictureBox1
  420. //
  421. this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  422. | System.Windows.Forms.AnchorStyles.Left)
  423. | System.Windows.Forms.AnchorStyles.Right)));
  424. this.pictureBox1.Location = new System.Drawing.Point(3, 3);
  425. this.pictureBox1.Name = "pictureBox1";
  426. this.pictureBox1.Size = new System.Drawing.Size(610, 524);
  427. this.pictureBox1.TabIndex = 2;
  428. this.pictureBox1.TabStop = false;
  429. this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
  430. this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
  431. this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);
  432. //
  433. // panel1
  434. //
  435. this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  436. | System.Windows.Forms.AnchorStyles.Left)));
  437. this.panel1.Controls.Add(this.splitContainer1);
  438. this.panel1.Location = new System.Drawing.Point(4, 5);
  439. this.panel1.Name = "panel1";
  440. this.panel1.Size = new System.Drawing.Size(810, 532);
  441. this.panel1.TabIndex = 27;
  442. this.panel1.SizeChanged += new System.EventHandler(this.panel1_SizeChanged);
  443. //
  444. // ImageIndexDialog
  445. //
  446. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  447. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  448. this.ClientSize = new System.Drawing.Size(818, 542);
  449. this.Controls.Add(this.panel1);
  450. this.MinimumSize = new System.Drawing.Size(212, 489);
  451. this.Name = "ImageIndexDialog";
  452. this.Text = "图像索引";
  453. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ImageIndexDialog_FormClosing);
  454. this.SizeChanged += new System.EventHandler(this.ImageIndexDialog_SizeChanged);
  455. this.Resize += new System.EventHandler(this.ImageIndexDialog_Resize);
  456. this.Controls.SetChildIndex(this.panel1, 0);
  457. this.groupBox1.ResumeLayout(false);
  458. this.groupBox2.ResumeLayout(false);
  459. this.groupBox2.PerformLayout();
  460. this.contextMenuStrip1.ResumeLayout(false);
  461. this.splitContainer1.Panel1.ResumeLayout(false);
  462. this.splitContainer1.Panel2.ResumeLayout(false);
  463. ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
  464. this.splitContainer1.ResumeLayout(false);
  465. ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
  466. this.panel1.ResumeLayout(false);
  467. this.ResumeLayout(false);
  468. }
  469. #endregion
  470. private System.Windows.Forms.GroupBox groupBox1;
  471. public System.Windows.Forms.ListView listView1;
  472. private System.Windows.Forms.ImageList imageList1;
  473. #endregion
  474. private AppWorkspace AppWorkspace;
  475. private ConfigModel config = Startup.instance.configModel;
  476. /// <summary>
  477. /// 当前document的图片
  478. /// </summary>
  479. private Bitmap imageMat;
  480. /// <summary>
  481. /// picturebox中图片对应矩形
  482. /// </summary>
  483. private Rectangle imageRect;
  484. /// <summary>
  485. /// picturebox中红框对应矩形
  486. /// </summary>
  487. private Rectangle zoomRect;
  488. /// <summary>
  489. /// picturebox中红框的最小宽度(原图放大3200%)
  490. /// </summary>
  491. private int minRectWidth;
  492. /// <summary>
  493. /// picturebox中红框的最小高度(原图放大3200%)
  494. /// </summary>
  495. private int minRectHeight;
  496. /// <summary>
  497. /// 当前document窗口与其缩放后的图片宽度比例
  498. /// </summary>
  499. private double widthRatio;
  500. /// <summary>
  501. /// 当前document窗口与其缩放后的图片高度比例
  502. /// </summary>
  503. private double heightRatio;
  504. /// <summary>
  505. /// picturebox中缩略图与document中缩放后图片的宽度比例(计算滚动条使用)
  506. /// </summary>
  507. private double scRatioWidth;
  508. /// <summary>
  509. /// picturebox中缩略图与document中缩放后图片的高度比例(计算滚动条使用)
  510. /// </summary
  511. private double scRatioHeight;
  512. /// <summary>
  513. /// 是否重置picturebox中的矩形尺寸
  514. /// </summary>
  515. private bool isFirst = true;
  516. /// <summary>
  517. /// 是否为拖动picturebox中的矩形框
  518. /// </summary>
  519. private bool isMoved = false;
  520. /// <summary>
  521. /// 是否为修改picturebox中的矩形框大小
  522. /// </summary>
  523. private bool isResized = false;
  524. /// <summary>
  525. /// 1-T1,2-T2,3-T3
  526. /// </summary>
  527. private int CurrentLocation = -1;
  528. /// <summary>
  529. /// 折叠状态,拉伸窗体,最小宽度等于最大宽度时延展宽度
  530. /// </summary>
  531. public int extendWidth = 200;
  532. /// <summary>
  533. /// 折叠后,最小宽度与最大宽度相等时,固定展开宽度值
  534. /// </summary>
  535. public int fixedWidth = 834;
  536. private Button button8;
  537. private Button button7;
  538. private ToolTip toolTip1;
  539. private Button btn_Hide;
  540. private GroupBox groupBox2;
  541. private Button btn_DelT3;
  542. private Button btn_DelT2;
  543. private Button btn_DelT1;
  544. private Button btn_AddT3;
  545. private Button btn_AddT2;
  546. private Button btn_AddT1;
  547. private Label label3;
  548. private Label label2;
  549. private Label label1;
  550. public ComboBox comboBox_T3;
  551. public ComboBox comboBox_T2;
  552. public ComboBox comboBox_T1;
  553. private Button btn_SetUp;
  554. private ComboBox comboBox_Name;
  555. private Button button10;
  556. private ContextMenuStrip contextMenuStrip1;
  557. private ToolStripMenuItem toolStripMenuItem1;
  558. private ToolStripMenuItem toolStripMenuItem2;
  559. private ToolStripMenuItem toolStripMenuItem3;
  560. private ToolStripMenuItem toolStripMenuItem4;
  561. public SplitContainer splitContainer1;
  562. /// <summary>
  563. /// 辅助计算偏移量
  564. /// </summary>
  565. private Point lastPoint = new Point(0, 0);
  566. public int fromMaxSize = 0;//折叠前窗体宽度
  567. public int fromMinSize = 0;//折叠后窗体宽度
  568. public ImageIndexDialog(AppWorkspace AppWorkspace)
  569. {
  570. imageIndexDialog = this;
  571. //this.fromMaxSize = this.Width;
  572. this.AppWorkspace = AppWorkspace;
  573. InitializeComponent();
  574. CollapseUnfold();
  575. InitializeButtonBackgroudImage();
  576. InitializeToolTipAndEvent();
  577. this.Text = PdnResources.GetString("Menu.Tools.ImageIndex.Text");
  578. this.groupBox1.Text = PdnResources.GetString("Menu.tool.Imageindex.Indexlist.text");
  579. this.groupBox2.Text = PdnResources.GetString("Menu.Set.Generalsettings.Namingrules.text");
  580. //
  581. // dialog
  582. //
  583. this.StartPosition = FormStartPosition.CenterScreen;
  584. this.Text = PdnResources.GetString("Menu.Tools.ImageIndex.Text");
  585. //
  586. // 设置listview事件
  587. //
  588. this.listView1.SelectedIndexChanged += new EventHandler(ListViewSelectedIndexChanged);
  589. comboBox_Name_Refresh();
  590. NamingInitialization();
  591. //
  592. // 初始化数据
  593. //
  594. this.InitData();
  595. this.listView1.View = View.LargeIcon;
  596. //PreviewRefresh();
  597. //SplitContainerSize();
  598. PreviewRefresh(config.CaptureSaveMode);
  599. }
  600. //初始化折叠与展开初始值
  601. private void CollapseUnfold()
  602. {
  603. this.fromMinSize = splitContainer1.Panel1.Width;
  604. this.fromMaxSize = this.Width;
  605. if (btn_Hide.Text == "<<")
  606. this.MaximumSize = new Size(0, 0);
  607. else
  608. this.MaximumSize = new Size(400, Screen.PrimaryScreen.Bounds.Height);
  609. this.groupBox1.MaximumSize = new Size(366, Screen.PrimaryScreen.Bounds.Height);
  610. }
  611. private void InitializeButtonBackgroudImage()
  612. {
  613. this.button7.FlatStyle = FlatStyle.Flat;
  614. this.button7.FlatAppearance.BorderSize = 0;
  615. this.button7.BackgroundImageLayout = ImageLayout.Center;
  616. this.button7.BackgroundImage = PdnResources.GetImageResource("Icons.ProjectEngineering.ListMode.png").Reference;
  617. this.button8.FlatStyle = FlatStyle.Flat;
  618. this.button8.FlatAppearance.BorderSize = 0;
  619. this.button8.BackgroundImageLayout = ImageLayout.Center;
  620. this.button8.BackgroundImage = PdnResources.GetImageResource("Icons.ProjectEngineering.PicMode.png").Reference;
  621. this.button10.FlatStyle = FlatStyle.Flat;
  622. this.button10.FlatAppearance.BorderSize = 0;
  623. this.button10.BackgroundImageLayout = ImageLayout.Center;
  624. this.button10.BackgroundImage = PdnResources.GetImageResource("Icons.MenuFileBulkSaveIcon.png").Reference;
  625. this.toolStripMenuItem1.Image = PdnResources.GetImageResource("Icons.MenuFileSaveIcon.png").Reference;
  626. this.toolStripMenuItem2.Image = PdnResources.GetImageResource("Icons.MenuFileSaveAsIcon.png").Reference;
  627. this.toolStripMenuItem3.Image = PdnResources.GetImageResource("Icons.MenuFileCloseIcon.png").Reference;
  628. this.toolStripMenuItem4.Image = PdnResources.GetImageResource("Icons.MenuEditCopyIcon.png").Reference;
  629. }
  630. /// <summary>
  631. /// 初始化提示信息及按钮事件
  632. /// </summary>
  633. private void InitializeToolTipAndEvent()
  634. {
  635. this.toolTip1 = new ToolTip();
  636. this.toolTip1.SetToolTip(this.button7, PdnResources.GetString("Menu.tool.Templatemanent.Listmode.text"));
  637. this.toolTip1.SetToolTip(this.button8, PdnResources.GetString("Menu.tool.Templategement.Thumbnailmode.text"));
  638. this.toolTip1.SetToolTip(this.button10, "批量保存");
  639. this.toolTip1.SetToolTip(this.btn_Hide, "折叠&展开");
  640. this.toolTip1.ShowAlways = true;
  641. }
  642. /// <summary>
  643. /// ListView选择事件
  644. /// </summary>
  645. /// <param name="sender"></param>
  646. /// <param name="e"></param>
  647. private void ListViewSelectedIndexChanged(object sender, EventArgs e)
  648. {
  649. if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Selected)
  650. {
  651. if (AppWorkspace.toInitImageIndexDialogFlag != 1)
  652. {
  653. AppWorkspace.toInitImageIndexDialogFlag = 2;
  654. AppWorkspace.ActiveDocumentWorkspace = AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index];
  655. }
  656. this.imageMat = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap();
  657. isFirst = true;
  658. lastPoint.X = 0;
  659. lastPoint.Y = 0;
  660. refreshSizeMode();
  661. }
  662. }
  663. /// <summary>
  664. /// 初始化图片列表数据
  665. /// </summary>
  666. public void InitData()
  667. {//需要优化调用的时机,隐藏时切换图片不需要切换,显示时显示图片。并且隐藏时置为null,显示时读取当前mat。
  668. //return;
  669. this.imageList1.Images.Clear();
  670. this.listView1.Items.Clear();
  671. this.listView1.Columns.Clear();
  672. //this.pictureBox1.Image = null;
  673. if (AppWorkspace.DocumentWorkspaces.Length == 0 || AppWorkspace.ActiveDocumentWorkspace == null)
  674. {
  675. this.listView1.Refresh();
  676. this.pictureBox1.Image = null;
  677. return;
  678. }
  679. int typeLenth = 70;
  680. int nameLenth = 100;
  681. if (this.listView1.Width > 310)
  682. {
  683. typeLenth = this.listView1.Width / 5;
  684. nameLenth = this.listView1.Width * 2 / 5;
  685. if (typeLenth > 70)
  686. {
  687. typeLenth = 70;
  688. nameLenth = this.listView1.Width - 215;
  689. }
  690. }
  691. ColumnHeader header = new ColumnHeader();
  692. header.Text = PdnResources.GetString("Menu.File.Text");
  693. header.Width = nameLenth;
  694. this.listView1.Columns.Add(header);
  695. header = new ColumnHeader();
  696. header.Text = PdnResources.GetString("Menu.Type.text");
  697. header.Width = typeLenth;
  698. this.listView1.Columns.Add(header);
  699. header = new ColumnHeader();
  700. header.Text = PdnResources.GetString("Menu.size.text");
  701. header.Width = typeLenth;
  702. this.listView1.Columns.Add(header);
  703. header = new ColumnHeader();
  704. header.Text = PdnResources.GetString("MeasurementUnit.Pixel");
  705. header.Width = typeLenth;
  706. this.listView1.Columns.Add(header);
  707. this.imageList1.ImageSize = new Size(this.listView1.Width - 91 > 250 ? 250 : this.listView1.Width - 91, this.listView1.Width - 91 > 250 ? 250 : this.listView1.Width - 91);
  708. //初始化图片列表
  709. for (int i = 0; i < AppWorkspace.DocumentWorkspaces.Length; i++)
  710. {
  711. DocumentWorkspace iDocumentWorkspace = AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - i];
  712. //added begin by songxk
  713. //added end by songxk
  714. this.imageList1.Images.Add("img" + i, OpenCvSharp.Extensions.BitmapConverter.ToBitmap(iDocumentWorkspace.BoxMat));
  715. this.listView1.Items.Add("", i);
  716. this.listView1.Items[i].ImageIndex = i;
  717. this.listView1.Items[i].Text = iDocumentWorkspace.GetFriendlyName();
  718. this.listView1.Items[i].Name = iDocumentWorkspace.GetFriendlyName();
  719. string type = "";
  720. if (iDocumentWorkspace.GetFriendlyName().IndexOf('.') > -1)
  721. {
  722. type = iDocumentWorkspace.GetFriendlyName().Substring(iDocumentWorkspace.GetFriendlyName().LastIndexOf('.') + 1, iDocumentWorkspace.GetFriendlyName().Length - iDocumentWorkspace.GetFriendlyName().LastIndexOf('.') - 1);
  723. }
  724. else
  725. {
  726. type = "";
  727. }
  728. this.imageMat = iDocumentWorkspace.CompositionSurface.CreateAliasedBitmap();
  729. //图片类型
  730. this.listView1.Items[i].SubItems.Add(type);
  731. //获取图片路径
  732. string fileName;
  733. //FileType fileType;
  734. //SaveConfigToken saveConfigToken;
  735. iDocumentWorkspace.GetDocumentSaveOptions(out fileName/*, out fileType, out saveConfigToken*/);
  736. //获取图片信息
  737. if (fileName != null)
  738. {
  739. //获取图片对应xml
  740. PicConfigModel configModel = null;
  741. try
  742. {
  743. string path = Path.GetDirectoryName(fileName);
  744. string xmlPath = path + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".xml";
  745. //如果xml存在
  746. if (System.IO.File.Exists(xmlPath))
  747. {
  748. configModel = XmlSerializeHelper.DESerializer<PicConfigModel>(FileOperationHelper.ReadStringFromFile(xmlPath, FileMode.Open));
  749. if (configModel != null)
  750. {
  751. //图片大小
  752. this.listView1.Items[i].SubItems.Add(configModel.meta.imageSize);
  753. }
  754. }
  755. else
  756. {
  757. //获取图片信息
  758. if (System.IO.File.Exists(fileName))
  759. {
  760. FileInfo fi = new FileInfo(fileName);
  761. //图片大小
  762. this.listView1.Items[i].SubItems.Add(FileOperationHelper.GetLength(fi.Length));
  763. }
  764. }
  765. }
  766. catch (Exception)
  767. {
  768. }
  769. }
  770. else
  771. {
  772. //图像若没有信息像素计算
  773. double length = imageMat.Width * imageMat.Height;
  774. double lengthKb = length * 24 /8 / 1024 / 4.77;
  775. double lengthMb = length * 24/ 8 / 1024 / 1024 / 4.77;
  776. if (lengthKb >= 1024)
  777. {
  778. this.listView1.Items[i].SubItems.Add(lengthMb.ToString("f2") + "M");
  779. }
  780. else
  781. {
  782. this.listView1.Items[i].SubItems.Add(lengthKb.ToString("f0") + "KB");
  783. }
  784. }
  785. //图片像素
  786. this.listView1.Items[i].SubItems.Add(imageMat.Width.ToString() + "*" + imageMat.Height.ToString());
  787. }
  788. if (index != -1)
  789. {
  790. this.listView1.Items[index].Focused = true;
  791. this.listView1.Items[index].Selected = true;
  792. }
  793. else
  794. {
  795. if (this.listView1.Items.Count > 0 && AppWorkspace.DocumentWorkspaces.Length > 0 && AppWorkspace.ActiveDocumentWorkspace != null)
  796. {
  797. this.listView1.Items[0].Focused = true;
  798. this.listView1.Items[0].Selected = true;
  799. }
  800. }
  801. }
  802. /// <summary>
  803. /// 根据图片尺寸判断picturebox的显示模式并刷新图片
  804. /// </summary>
  805. private void refreshSizeMode()
  806. {
  807. if (imageMat != null)
  808. {
  809. if (imageMat.Width > pictureBox1.Size.Width || imageMat.Height > pictureBox1.Size.Height)
  810. {
  811. pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
  812. }
  813. else
  814. {
  815. pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
  816. }
  817. this.pictureBox1.Image = imageMat;
  818. }
  819. }
  820. /// <summary>
  821. /// 窗体尺寸改变
  822. /// </summary>
  823. /// <param name="sender"></param>
  824. /// <param name="e"></param>
  825. private void ImageIndexDialog_Resize(object sender, EventArgs e)
  826. {
  827. lastPoint.X = 0;
  828. lastPoint.Y = 0;
  829. isFirst = true;
  830. refreshSizeMode();
  831. }
  832. /// <summary>
  833. /// 绘制picturebox
  834. /// </summary>
  835. /// <param name="sender"></param>
  836. /// <param name="e"></param>
  837. private void pictureBox1_Paint(object sender, PaintEventArgs e)
  838. {
  839. if (this.pictureBox1.Image != null)
  840. {
  841. if (isFirst)
  842. {
  843. //获取缩略图对应矩形
  844. PropertyInfo _ImageRectanglePropert = this.pictureBox1.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic);
  845. imageRect = (Rectangle)_ImageRectanglePropert.GetValue(this.pictureBox1, null);
  846. Size size = AppWorkspace.ActiveDocumentWorkspace.panel.ClientSize;//document窗体尺寸
  847. double ratio = AppWorkspace.ActiveDocumentWorkspace.ScaleRatio;
  848. if (size.Width < this.imageMat.Width * ratio)
  849. widthRatio = size.Width / (this.imageMat.Width * ratio);
  850. else
  851. widthRatio = 1;
  852. if (size.Height < this.imageMat.Height * ratio)
  853. heightRatio = size.Height / (this.imageMat.Height * ratio);
  854. else
  855. heightRatio = 1;
  856. Point scPoint = AppWorkspace.ActiveDocumentWorkspace.PanelScrollPosition;//当前滚动条位置
  857. scRatioWidth = imageRect.Width / (imageMat.Width * ratio);
  858. scRatioHeight = imageRect.Height / (imageMat.Height * ratio);
  859. //缩略图中红框选中区域
  860. zoomRect = new Rectangle(imageRect.X + (int)(scPoint.X * scRatioWidth), imageRect.Y + (int)(scPoint.Y * scRatioHeight),
  861. (int)(imageRect.Width * widthRatio), (int)(imageRect.Height * heightRatio));
  862. //红框矩形的最小尺寸,即原图放大3200%
  863. double minWidthRatio = size.Width / (this.imageMat.Width * 32d);
  864. double minHeightRatio = size.Height / (this.imageMat.Height * 32d);
  865. minRectWidth = (int)(Math.Round(imageRect.Width * minWidthRatio));
  866. minRectHeight = (int)(Math.Round(imageRect.Height * minHeightRatio));
  867. }
  868. e.Graphics.DrawRectangle(new Pen(Color.Red), zoomRect.X, zoomRect.Y, zoomRect.Width - 1, zoomRect.Height - 1);
  869. e.Graphics.FillRectangle(new SolidBrush(Color.Black), new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 9, 9));
  870. }
  871. }
  872. /// <summary>
  873. /// picturebox的鼠标按下事件
  874. /// </summary>
  875. /// <param name="sender"></param>
  876. /// <param name="e"></param>
  877. private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
  878. {
  879. lastPoint.X = e.X;
  880. lastPoint.Y = e.Y;
  881. //是否平移
  882. if (zoomRect.Contains(e.Location) && !new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 9, 9).Contains(e.Location))
  883. isMoved = true;
  884. else
  885. isMoved = false;
  886. //是否放大缩小
  887. if (new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 9, 9).Contains(e.Location))
  888. isResized = true;
  889. else
  890. isResized = false;
  891. }
  892. /// <summary>
  893. /// pocturebox的鼠标移动事件
  894. /// </summary>
  895. /// <param name="sender"></param>
  896. /// <param name="e"></param>
  897. private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
  898. {
  899. //修改鼠标形状
  900. this.pictureBox1.Cursor = Cursors.Default;
  901. if (zoomRect != null)
  902. {
  903. if (zoomRect.Contains(e.Location) && !new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 9, 9).Contains(e.Location))
  904. {
  905. this.pictureBox1.Cursor = Cursors.SizeAll;
  906. }
  907. if (new Rectangle(zoomRect.Right - 4, zoomRect.Bottom - 4, 7, 7).Contains(e.Location))
  908. {
  909. this.pictureBox1.Cursor = Cursors.SizeNWSE;
  910. }
  911. }
  912. if (e.Button != MouseButtons.Left)
  913. return;
  914. //拖拽
  915. if (zoomRect != null && isMoved)
  916. {
  917. isFirst = false;
  918. Point p = e.Location;
  919. int dx = p.X - lastPoint.X;
  920. int dy = p.Y - lastPoint.Y;
  921. lastPoint.X = p.X;
  922. lastPoint.Y = p.Y;
  923. zoomRect.X += dx;
  924. zoomRect.Y += dy;
  925. //控制矩形框不超过缩略图尺寸
  926. int xc = (this.pictureBox1.Width - this.imageRect.Width) / 2;
  927. int yc = (this.pictureBox1.Height - this.imageRect.Height) / 2;
  928. if (zoomRect.X < xc) zoomRect.X = xc;
  929. if (zoomRect.Y < yc) zoomRect.Y = yc;
  930. if (zoomRect.X + zoomRect.Width > imageRect.Width + xc) zoomRect.X = imageRect.Width - zoomRect.Width + xc;
  931. if (zoomRect.Y + zoomRect.Height > imageRect.Height + yc) zoomRect.Y = imageRect.Height - zoomRect.Height + yc;
  932. this.pictureBox1.Refresh();
  933. //修改document的滚动条
  934. Point scPoint = AppWorkspace.ActiveDocumentWorkspace.PanelScrollPosition;
  935. double scrollDx = dx / scRatioWidth;
  936. double scrollDy = dy / scRatioHeight;
  937. Point newScPoint = new Point(scPoint.X + Convert.ToInt32(Math.Round(scrollDx)), scPoint.Y + Convert.ToInt32(Math.Round(scrollDy)));
  938. AppWorkspace.ActiveDocumentWorkspace.PanelScrollPosition = newScPoint;
  939. }
  940. //缩放
  941. if (zoomRect != null && isResized)
  942. {
  943. isFirst = false;
  944. Point p = e.Location;
  945. int dx = p.X - lastPoint.X;
  946. int dy = p.Y - lastPoint.Y;
  947. lastPoint.X = p.X;
  948. lastPoint.Y = p.Y;
  949. //偏移量取横坐标与纵坐标中绝对值大的
  950. int delta = dx;
  951. if (Math.Abs(dy) > Math.Abs(dx))
  952. delta = dy;
  953. Size size = AppWorkspace.ActiveDocumentWorkspace.panel.ClientSize;//document尺寸
  954. double ratio = AppWorkspace.ActiveDocumentWorkspace.ScaleRatio;//缩放比
  955. //图片缩放后的宽和高都小于document窗口尺寸
  956. if (size.Width > this.imageMat.Width * ratio && size.Height > this.imageMat.Height * ratio)
  957. {
  958. AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;//修改缩放模式
  959. //只修改缩放比,不改变缩略图矩形框尺寸
  960. ratio += (-delta / 100d);
  961. ratio = GetMinRatio(ratio);
  962. RefreshActiveDocumentScaleFactor(ratio);
  963. }
  964. //图片缩放后的宽和高大于等于doucment窗口尺寸
  965. else
  966. {
  967. double aspectRatio = size.Width / (size.Height * 1d);//宽高比
  968. int maxResizedWidth = imageRect.Right - zoomRect.Right;//正向最大拖动宽度
  969. int maxResizedHeigth = imageRect.Bottom - zoomRect.Bottom;//正向最大拖动高度
  970. int maxRectWidth = maxResizedWidth + zoomRect.Width;//小矩形可放大到的最大宽度
  971. int maxRectHeight = maxResizedHeigth + zoomRect.Height;//小矩形可放大到的最大高度
  972. double newScaleRatio = 0;//计算后新的缩放比
  973. double newScPointX = 0;//计算后新的滚动条横坐标
  974. double newScPointY = 0;//计算后新的滚动条纵坐标
  975. //图片缩放后只有宽小于ducument窗口尺寸
  976. if (size.Width > this.imageMat.Width * ratio && size.Height <= this.imageMat.Height * ratio)
  977. {
  978. int minHeight = (int)Math.Round(imageRect.Width / aspectRatio);//矩形框可拖动的最小高度
  979. zoomRect.Height += delta;
  980. if (zoomRect.Height > maxRectHeight)
  981. {
  982. zoomRect.Height = maxRectHeight;
  983. //矩形框的起始点不在缩略图的起始点上时,高度达到默认可变的最大值后,同时修改纵坐标和高度
  984. if (maxRectHeight < imageRect.Height)
  985. {
  986. zoomRect.Y -= delta;
  987. if (zoomRect.Y < imageRect.Y)
  988. zoomRect.Y = imageRect.Y;
  989. zoomRect.Height += delta;
  990. if (zoomRect.Height > imageRect.Height)
  991. zoomRect.Height = imageRect.Height;
  992. this.pictureBox1.Refresh();
  993. newScaleRatio = Math.Round(size.Height / heightRatio / this.imageMat.Height, 2);//重新计算缩放比
  994. newScaleRatio = GetMinRatio(newScaleRatio);
  995. //重新计算滚轮所需比例
  996. scRatioWidth = imageRect.Width / (imageMat.Width * newScaleRatio);
  997. scRatioHeight = imageRect.Height / (imageMat.Height * newScaleRatio);
  998. //重新计算document的滚动条横坐标与纵坐标
  999. newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
  1000. newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
  1001. RefreshActiveDocumentScaleFactorAndScroll(ratio, new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY)));
  1002. return;
  1003. }
  1004. //高度达到极限,只改变缩放比
  1005. this.pictureBox1.Refresh();
  1006. ratio += (-delta / 100d);
  1007. ratio = GetMinRatio(ratio);
  1008. RefreshActiveDocumentScaleFactor(ratio);
  1009. return;
  1010. }
  1011. if (zoomRect.Height < minHeight)
  1012. zoomRect.Height = minHeight;
  1013. this.pictureBox1.Refresh();
  1014. heightRatio = zoomRect.Height / (imageRect.Height * 1d);
  1015. heightRatio = GetMaxDocumentWithBitmapRatio(heightRatio);
  1016. newScaleRatio = Math.Round(size.Height / heightRatio / this.imageMat.Height, 2);//重新计算缩放比
  1017. }
  1018. //图片缩放后只有高小于ducument窗口尺寸
  1019. if (size.Width <= this.imageMat.Width * ratio && size.Height > this.imageMat.Height * ratio)
  1020. {
  1021. int minWidth = (int)Math.Round(imageRect.Height * aspectRatio);//矩形框可拖动的最小宽度
  1022. zoomRect.Width += delta;
  1023. if (zoomRect.Width > maxRectWidth)
  1024. {
  1025. zoomRect.Width = maxRectWidth;
  1026. //矩形框的起始点不在缩略图的起始点上时,宽度达到默认可变的最大值后,同时修改横坐标和宽度
  1027. if (maxRectWidth < imageRect.Width)
  1028. {
  1029. zoomRect.X -= delta;
  1030. if (zoomRect.X < imageRect.X)
  1031. zoomRect.X = imageRect.X;
  1032. zoomRect.Width += delta;
  1033. if (zoomRect.Width > imageRect.Width)
  1034. zoomRect.Width = imageRect.Width;
  1035. this.pictureBox1.Refresh();
  1036. newScaleRatio = Math.Round(size.Width / widthRatio / this.imageMat.Width, 2);//重新计算缩放比
  1037. newScaleRatio = GetMinRatio(newScaleRatio);
  1038. //重新计算滚轮所需比例
  1039. scRatioWidth = imageRect.Width / (imageMat.Width * newScaleRatio);
  1040. scRatioHeight = imageRect.Height / (imageMat.Height * newScaleRatio);
  1041. //重新计算document的滚动条横坐标与纵坐标
  1042. newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
  1043. newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
  1044. RefreshActiveDocumentScaleFactorAndScroll(newScaleRatio, new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY)));
  1045. return;
  1046. }
  1047. //宽度达到极限,改变缩放比
  1048. this.pictureBox1.Refresh();
  1049. ratio += (-delta / 100d);
  1050. ratio = GetMinRatio(ratio);
  1051. RefreshActiveDocumentScaleFactor(ratio);
  1052. return;
  1053. }
  1054. if (zoomRect.Width < minWidth)
  1055. zoomRect.Width = minWidth;
  1056. this.pictureBox1.Refresh();
  1057. widthRatio = zoomRect.Width / (imageRect.Width * 1d);
  1058. widthRatio = GetMaxDocumentWithBitmapRatio(widthRatio);
  1059. newScaleRatio = Math.Round(size.Width / widthRatio / this.imageMat.Width, 2);//重新计算缩放比
  1060. }
  1061. //图片缩放后的宽和高都不小于document窗体尺寸
  1062. if (size.Width <= this.imageMat.Width * ratio && size.Height <= this.imageMat.Height * ratio)
  1063. {
  1064. if (maxResizedWidth < maxResizedHeigth)
  1065. {
  1066. zoomRect.Width += delta;
  1067. if (zoomRect.Width > maxRectWidth)
  1068. {
  1069. zoomRect.Width = maxRectWidth;
  1070. //矩形框的宽度与缩略图宽度相同时才可改变高度并调整缩放比
  1071. if(zoomRect.Width >= imageRect.Width)
  1072. {
  1073. zoomRect.Height += delta;
  1074. this.pictureBox1.Refresh();
  1075. heightRatio = zoomRect.Height / (imageRect.Height * 1d);
  1076. heightRatio = GetMaxDocumentWithBitmapRatio(heightRatio);
  1077. newScaleRatio = Math.Round(size.Height / heightRatio / this.imageMat.Height, 2);//重新计算缩放比
  1078. newScaleRatio = GetMinRatio(newScaleRatio);
  1079. //重新计算滚轮所需比例
  1080. scRatioWidth = imageRect.Width / (imageMat.Width * newScaleRatio);
  1081. scRatioHeight = imageRect.Height / (imageMat.Height * newScaleRatio);
  1082. //重新计算document的滚动条横坐标与纵坐标
  1083. newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
  1084. newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
  1085. RefreshActiveDocumentScaleFactorAndScroll(newScaleRatio, new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY)));
  1086. return;
  1087. }
  1088. }
  1089. if (zoomRect.Width < minRectWidth)
  1090. zoomRect.Width = minRectWidth;
  1091. zoomRect.Height = (int)Math.Round(zoomRect.Width / aspectRatio);
  1092. }
  1093. else
  1094. {
  1095. zoomRect.Height += delta;
  1096. if (zoomRect.Height > maxRectHeight)
  1097. {
  1098. zoomRect.Height = maxRectHeight;
  1099. //矩形框的高度与缩略图高度相同时才可改变宽度并调整缩放比
  1100. if (zoomRect.Height >= imageRect.Height)
  1101. {
  1102. zoomRect.Width += delta;
  1103. this.pictureBox1.Refresh();
  1104. widthRatio = zoomRect.Width / (imageRect.Width * 1d);
  1105. widthRatio = GetMaxDocumentWithBitmapRatio(widthRatio);
  1106. newScaleRatio = Math.Round(size.Width / widthRatio / this.imageMat.Width, 2);//重新计算缩放比
  1107. newScaleRatio = GetMinRatio(newScaleRatio);
  1108. //重新计算滚轮所需比例
  1109. scRatioWidth = imageRect.Width / (imageMat.Width * newScaleRatio);
  1110. scRatioHeight = imageRect.Height / (imageMat.Height * newScaleRatio);
  1111. //重新计算document的滚动条横坐标与纵坐标
  1112. newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
  1113. newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
  1114. RefreshActiveDocumentScaleFactorAndScroll(newScaleRatio, new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY)));
  1115. return;
  1116. }
  1117. }
  1118. if (zoomRect.Height < minRectHeight)
  1119. zoomRect.Height = minRectHeight;
  1120. zoomRect.Width = (int)Math.Round(zoomRect.Height * aspectRatio);
  1121. }
  1122. this.pictureBox1.Refresh();
  1123. //重新计算比例
  1124. widthRatio = zoomRect.Width / (imageRect.Width * 1d);
  1125. widthRatio = GetMaxDocumentWithBitmapRatio(widthRatio);
  1126. heightRatio = zoomRect.Height / (imageRect.Height * 1d);
  1127. heightRatio = GetMaxDocumentWithBitmapRatio(heightRatio);
  1128. //计算document的缩放比,宽和高的计算结果会有细微差异
  1129. double scaleW = Math.Round(size.Width / widthRatio / this.imageMat.Width, 2);
  1130. double scaleH = Math.Round(size.Height / heightRatio / this.imageMat.Height, 2);
  1131. //取大的值作为新的缩放比?不确定
  1132. if (scaleW >= scaleH)
  1133. newScaleRatio = scaleW;
  1134. else
  1135. newScaleRatio = scaleH;
  1136. }
  1137. //重新计算滚轮所需比例
  1138. scRatioWidth = imageRect.Width / (imageMat.Width * newScaleRatio);
  1139. scRatioHeight = imageRect.Height / (imageMat.Height * newScaleRatio);
  1140. //重新计算document的滚动条横坐标与纵坐标
  1141. newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
  1142. newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
  1143. RefreshActiveDocumentScaleFactorAndScroll(newScaleRatio, new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY)));
  1144. }
  1145. }
  1146. }
  1147. /// <summary>
  1148. /// 控制缩放比的最小值为1%
  1149. /// </summary>
  1150. /// <param name="ratio"></param>
  1151. /// <returns></returns>
  1152. private double GetMinRatio(double ratio)
  1153. {
  1154. if (ratio < 0.01)
  1155. ratio = 0.01;
  1156. return ratio;
  1157. }
  1158. /// <summary>
  1159. /// 控制document窗口与缩放后图片比例,最大值为1
  1160. /// </summary>
  1161. /// <param name="ratio"></param>
  1162. /// <returns></returns>
  1163. private double GetMaxDocumentWithBitmapRatio(double ratio)
  1164. {
  1165. if (ratio > 1)
  1166. ratio = 1;
  1167. return ratio;
  1168. }
  1169. /// <summary>
  1170. /// 刷新当前激活document的缩放比
  1171. /// </summary>
  1172. /// <param name="scaleRatio"></param>
  1173. /// <returns></returns>
  1174. private bool RefreshActiveDocumentScaleFactor(double scaleRatio)
  1175. {
  1176. AppWorkspace.ActiveDocumentWorkspace.ScaleFactor = ScaleFactor.FromDouble(scaleRatio);
  1177. AppWorkspace.ActiveDocumentWorkspace.Refresh();
  1178. return true;
  1179. }
  1180. /// <summary>
  1181. /// 刷新当前激活document的缩放比与滚动条
  1182. /// </summary>
  1183. /// <param name="scaleRatio"></param>
  1184. /// <returns></returns>
  1185. private bool RefreshActiveDocumentScaleFactorAndScroll(double scaleRatio, Point point)
  1186. {
  1187. AppWorkspace.ActiveDocumentWorkspace.ScaleFactor = ScaleFactor.FromDouble(scaleRatio);
  1188. AppWorkspace.ActiveDocumentWorkspace.PanelScrollPosition = point;
  1189. AppWorkspace.ActiveDocumentWorkspace.Refresh();
  1190. return true;
  1191. }
  1192. private void button7_Click(object sender, EventArgs e)
  1193. {
  1194. if (this.listView1.View == View.Details)
  1195. return;
  1196. for (int i = 0; i < this.listView1.Items.Count; i++)
  1197. {
  1198. if (AppWorkspace.DocumentWorkspaces[i].GetFriendlyName().IndexOf('.') > -1)
  1199. {
  1200. this.listView1.Items[i].Text = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName().Substring(0, AppWorkspace.DocumentWorkspaces[i].GetFriendlyName().LastIndexOf('.'));
  1201. this.listView1.Items[i].Name = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName().Substring(0, AppWorkspace.DocumentWorkspaces[i].GetFriendlyName().LastIndexOf('.'));
  1202. }
  1203. else
  1204. {
  1205. this.listView1.Items[i].Text = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  1206. this.listView1.Items[i].Name = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  1207. }
  1208. }
  1209. //string ssss = "333.44.555.666.jpg";
  1210. //int n = ssss.LastIndexOf(".");
  1211. //InitData();
  1212. this.listView1.View = View.Details;
  1213. }
  1214. private void button8_Click(object sender, EventArgs e)
  1215. {
  1216. if (this.listView1.View == View.LargeIcon)
  1217. return;
  1218. ////初始化图片列表
  1219. //for (int i = 0; i < this.listView1.Items.Count; i++)
  1220. //{
  1221. // this.listView1.Items[i].Text = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  1222. // this.listView1.Items[i].Name = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  1223. //}
  1224. this.imageList1.ImageSize = new Size(this.listView1.Width-91 > 250? 250: this.listView1.Width-91, this.listView1.Width-91 > 250 ? 250 : this.listView1.Width-91);
  1225. //InitData();
  1226. this.listView1.View = View.LargeIcon;
  1227. }
  1228. /// <summary>
  1229. /// 折叠展开
  1230. /// </summary>
  1231. /// <param name="sender"></param>
  1232. /// <param name="e"></param>
  1233. private void btn_Hide_Click(object sender, EventArgs e)
  1234. {
  1235. if (btn_Hide.Text == ">>" && this.fromMinSize == this.fromMaxSize)
  1236. {
  1237. this.fromMaxSize = fixedWidth;
  1238. }
  1239. if (this.Width == this.fromMinSize)
  1240. {
  1241. btn_Hide.Text = "<<";
  1242. this.MaximumSize = new Size(0,0);
  1243. this.Width = this.fromMaxSize;
  1244. }
  1245. else
  1246. {
  1247. btn_Hide.Text = ">>";
  1248. this.fromMaxSize = this.Width;
  1249. this.fromMinSize = splitContainer1.SplitterDistance +24;
  1250. this.Width = this.fromMinSize;
  1251. this.MaximumSize = new Size(400, this.Height);
  1252. //this.fromMinSize = this.Width;
  1253. }
  1254. }
  1255. /// <summary>
  1256. /// 配合折叠展开
  1257. /// </summary>
  1258. /// <param name="sender"></param>
  1259. /// <param name="e"></param>
  1260. private void ImageIndexDialog_SizeChanged(object sender, EventArgs e)
  1261. {
  1262. if (this.btn_Hide.Text == ">>")
  1263. {
  1264. splitContainer1.IsSplitterFixed = true;
  1265. splitContainer1.FixedPanel = FixedPanel.Panel1;
  1266. if (this.Width >= this.fromMaxSize)
  1267. {
  1268. panel1.Width = this.Width + extendWidth;
  1269. this.fromMaxSize = this.Width + extendWidth +24;
  1270. }
  1271. //if (this.Width <= this.fromMinSize)
  1272. //{
  1273. // panel1.Width = this.Width + 550;
  1274. // this.fromMaxSize = this.Width + 574;
  1275. //}
  1276. splitContainer1.SplitterDistance = this.Width - 24;
  1277. this.fromMinSize = this.Width;
  1278. return;
  1279. }
  1280. if (this.btn_Hide.Text == "<<")
  1281. {
  1282. splitContainer1.IsSplitterFixed = false;
  1283. splitContainer1.FixedPanel = FixedPanel.None;
  1284. splitContainer1.SplitterDistance = this.fromMinSize - 24;
  1285. this.fromMaxSize = this.Width;
  1286. }
  1287. if (this.Width > this.fromMinSize)
  1288. {
  1289. this.btn_Hide.Text = "<<";
  1290. if (this.MaximumSize.Width == 400)
  1291. this.MaximumSize = new Size(0, 0);
  1292. }
  1293. else
  1294. {
  1295. this.btn_Hide.Text = ">>";
  1296. if (this.MaximumSize.Width != 400)
  1297. this.MaximumSize = new Size(400, this.Height);
  1298. }
  1299. if (this.Width - 24 > panel1.Width || btn_Hide.Text == "<<" || this.Width > this.fromMinSize)
  1300. panel1.Width = this.Width - 24;
  1301. //if (this.btn_Hide.Text == ">>")
  1302. //{
  1303. // splitContainer1.IsSplitterFixed = true;
  1304. // splitContainer1.FixedPanel = FixedPanel.Panel1;
  1305. // //splitContainer1.SplitterDistance = this.Width - 24;
  1306. //}
  1307. //else
  1308. //{
  1309. // splitContainer1.IsSplitterFixed = false;
  1310. // splitContainer1.FixedPanel = FixedPanel.None;
  1311. //}
  1312. }
  1313. private void panel1_SizeChanged(object sender, EventArgs e)
  1314. {
  1315. splitContainer1.SplitterDistance = this.fromMinSize - 24;
  1316. }
  1317. private int index =-1;
  1318. private void splitContainer1_Panel1_SizeChanged(object sender, EventArgs e)
  1319. {
  1320. if (this.fromMinSize != splitContainer1.SplitterDistance + 24)
  1321. {
  1322. this.fromMinSize = splitContainer1.SplitterDistance + 24;
  1323. if (this.listView1.FocusedItem != null)
  1324. {
  1325. index = this.listView1.FocusedItem.Index;
  1326. InitData();
  1327. index = -1;
  1328. }
  1329. }
  1330. if (splitContainer1.SplitterDistance > 376)
  1331. {
  1332. splitContainer1.SplitterDistance = 376;
  1333. }
  1334. lblPreview.Width = splitContainer1.SplitterDistance - 22;
  1335. }
  1336. private void button10_Click(object sender, EventArgs e)
  1337. {
  1338. using (BatchSaveDialog dialog = new BatchSaveDialog(AppWorkspace))
  1339. {
  1340. if (AppWorkspace.startScriptRecording)
  1341. {
  1342. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  1343. }
  1344. dialog.StartPosition = FormStartPosition.CenterScreen;
  1345. dialog.ShowDialog();
  1346. }
  1347. }
  1348. /// <summary>
  1349. /// 命名规则设置
  1350. /// </summary>
  1351. /// <param name="sender"></param>
  1352. /// <param name="e"></param>
  1353. private void btn_SetUp_Click(object sender, EventArgs e)
  1354. {
  1355. if (AppWorkspace.startScriptRecording)
  1356. {
  1357. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  1358. }
  1359. using (GeneralSettingDialog af = new GeneralSettingDialog(AppWorkspace))
  1360. {
  1361. af.groupBox1.Visible = false;
  1362. af.groupBox2.Location = new Point(6,13);
  1363. af.groupBox5.Location = new Point(6, 136);
  1364. af.groupBox19.Location = new Point(6, 74);
  1365. af.Width = af.Width - af.groupBox1.Width;
  1366. af.StartPosition = FormStartPosition.CenterScreen;
  1367. af.ShowDialog(AppWorkspace);
  1368. }
  1369. }
  1370. public void PreviewRefresh(int mode = 0)
  1371. {
  1372. config.Txt1 = comboBox_T1.Text;
  1373. config.Txt2 = comboBox_T2.Text;
  1374. config.Txt3 = comboBox_T2.Text;
  1375. string photoName;
  1376. if (Startup.instance.ruleDB == null)
  1377. photoName = NamingRuleHelper.GetNameFromXml(Startup.instance.configModel, "默认标尺", "0", mode);
  1378. else
  1379. photoName = NamingRuleHelper.GetNameFromXml(Startup.instance.configModel, Startup.instance.ruleDB.ruler_name, Startup.instance.ruleDB.gain_multiple.ToString(), mode);
  1380. lblPreview.Text = photoName;
  1381. }
  1382. private void comboBox_T1_TextUpdate(object sender, EventArgs e)
  1383. {
  1384. PreviewRefresh(config.CaptureSaveMode);
  1385. }
  1386. private void comboBox_T2_TextUpdate(object sender, EventArgs e)
  1387. {
  1388. PreviewRefresh(config.CaptureSaveMode);
  1389. }
  1390. private void comboBox_T3_TextUpdate(object sender, EventArgs e)
  1391. {
  1392. PreviewRefresh(config.CaptureSaveMode);
  1393. }
  1394. /// <summary>
  1395. /// 刷新条目名称
  1396. /// </summary>
  1397. public void comboBox_Name_Refresh(int mode = 0)
  1398. {
  1399. this.comboBox_Name.SelectedIndexChanged -= new System.EventHandler(this.comboBox_Name_SelectedIndexChanged);
  1400. string[] lstName = config.LstNaming.Select(a => a.name).ToArray();
  1401. this.comboBox_Name.DataSource = lstName;
  1402. this.comboBox_Name.Text = config.CurrentName;
  1403. this.comboBox_Name.SelectedIndexChanged += new System.EventHandler(this.comboBox_Name_SelectedIndexChanged);
  1404. PreviewRefresh(mode);
  1405. }
  1406. /// <summary>
  1407. /// 添加自定义文本1
  1408. /// </summary>
  1409. /// <param name="sender"></param>
  1410. /// <param name="e"></param>
  1411. private void btn_AddT1_Click(object sender, EventArgs e)
  1412. {
  1413. if (comboBox_T1.Text.Trim() == "")
  1414. {
  1415. MessageBox.Show("参数不能为空!");
  1416. return;
  1417. };
  1418. CurrentLocation = 1;
  1419. CustomTxt customTxt = new CustomTxt();
  1420. customTxt.customT = comboBox_T1.Text.Trim();
  1421. if (config.LstCustomTxt == null) config.LstCustomTxt = new CustomTxtModel();
  1422. if (config.LstCustomTxt.customTxts1 == null) config.LstCustomTxt.customTxts1 = new List<CustomTxt>();
  1423. if (Inspect())
  1424. {
  1425. MessageBox.Show("名称重复!");
  1426. return;
  1427. }
  1428. config.LstCustomTxt.customTxts1.Add(customTxt);
  1429. config.Txt1 = comboBox_T1.Text.Trim();
  1430. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
  1431. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  1432. if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  1433. MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
  1434. if (config.LstCustomTxt.customTxts1 != null && config.LstCustomTxt.customTxts1.Count > 0)
  1435. {
  1436. string[] lstName = config.LstCustomTxt.customTxts1.Select(a => a.customT).ToArray();
  1437. this.comboBox_T1.DataSource = lstName;
  1438. if (lstName.Length > 0) this.comboBox_T1.Text = customTxt.customT;
  1439. }
  1440. else this.comboBox_T1.DataSource = null;
  1441. }
  1442. /// <summary>
  1443. /// 添加自定义文本2
  1444. /// </summary>
  1445. /// <param name="sender"></param>
  1446. /// <param name="e"></param>
  1447. private void btn_AddT2_Click(object sender, EventArgs e)
  1448. {
  1449. if (comboBox_T2.Text.Trim() == "")
  1450. {
  1451. MessageBox.Show("参数不能为空!");
  1452. return;
  1453. };
  1454. CurrentLocation = 2;
  1455. CustomTxt customTxt = new CustomTxt();
  1456. customTxt.customT = comboBox_T2.Text.Trim();
  1457. if (config.LstCustomTxt == null) config.LstCustomTxt = new CustomTxtModel();
  1458. if (config.LstCustomTxt.customTxts2 == null) config.LstCustomTxt.customTxts2 = new List<CustomTxt>();
  1459. if (Inspect())
  1460. {
  1461. MessageBox.Show("名称重复!");
  1462. return;
  1463. }
  1464. config.LstCustomTxt.customTxts2.Add(customTxt);
  1465. config.Txt2 = comboBox_T2.Text.Trim();
  1466. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
  1467. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  1468. if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  1469. MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
  1470. if (config.LstCustomTxt.customTxts2 != null && config.LstCustomTxt.customTxts2.Count > 0)
  1471. {
  1472. string[] lstName = config.LstCustomTxt.customTxts2.Select(a => a.customT).ToArray();
  1473. this.comboBox_T2.DataSource = lstName;
  1474. if (lstName.Length > 0) this.comboBox_T2.Text = customTxt.customT;
  1475. }
  1476. else this.comboBox_T2.DataSource = null;
  1477. }
  1478. private void TxtAssignment()
  1479. {
  1480. config.Txt1 = comboBox_T1.Text.Trim();
  1481. config.Txt2 = comboBox_T2.Text.Trim();
  1482. config.Txt3 = comboBox_T3.Text.Trim();
  1483. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
  1484. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  1485. if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  1486. MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
  1487. }
  1488. /// <summary>
  1489. /// 添加自定义文本3
  1490. /// </summary>
  1491. /// <param name="sender"></param>
  1492. /// <param name="e"></param>
  1493. private void btn_AddT3_Click(object sender, EventArgs e)
  1494. {
  1495. if (comboBox_T3.Text.Trim() == "")
  1496. {
  1497. MessageBox.Show("参数不能为空!");
  1498. return;
  1499. };
  1500. CurrentLocation = 3;
  1501. CustomTxt customTxt = new CustomTxt();
  1502. customTxt.customT = comboBox_T3.Text.Trim();
  1503. if (config.LstCustomTxt == null) config.LstCustomTxt = new CustomTxtModel();
  1504. if (config.LstCustomTxt.customTxts3 == null) config.LstCustomTxt.customTxts3 = new List<CustomTxt>();
  1505. if (Inspect())
  1506. {
  1507. MessageBox.Show("名称重复!");
  1508. return;
  1509. }
  1510. config.LstCustomTxt.customTxts3.Add(customTxt);
  1511. config.Txt3 = comboBox_T3.Text.Trim();
  1512. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
  1513. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  1514. if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  1515. MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
  1516. if (config.LstCustomTxt.customTxts3 != null && config.LstCustomTxt.customTxts3.Count > 0)
  1517. {
  1518. string[] lstName = config.LstCustomTxt.customTxts3.Select(a => a.customT).ToArray();
  1519. this.comboBox_T3.DataSource = lstName;
  1520. if (lstName.Length > 0) this.comboBox_T3.Text = customTxt.customT;
  1521. }
  1522. else this.comboBox_T3.DataSource = null;
  1523. }
  1524. //文本检查
  1525. private bool Inspect()
  1526. {
  1527. bool chek = false;
  1528. string name = string.Empty;
  1529. switch (CurrentLocation)
  1530. {
  1531. case 1:
  1532. name = comboBox_T1.Text.Trim();
  1533. if (config.LstCustomTxt.customTxts1.Count > 0)
  1534. {
  1535. string[] lstName = config.LstCustomTxt.customTxts1.Select(a => a.customT).ToArray();
  1536. chek = ((IList)lstName).Contains(name);
  1537. }
  1538. break;
  1539. case 2:
  1540. name = comboBox_T2.Text.Trim();
  1541. if (config.LstCustomTxt.customTxts2.Count > 0)
  1542. {
  1543. string[] lstName = config.LstCustomTxt.customTxts2.Select(a => a.customT).ToArray();
  1544. chek = ((IList)lstName).Contains(name);
  1545. }
  1546. break;
  1547. case 3:
  1548. name = comboBox_T3.Text.Trim();
  1549. if (config.LstCustomTxt.customTxts3.Count > 0)
  1550. {
  1551. string[] lstName = config.LstCustomTxt.customTxts3.Select(a => a.customT).ToArray();
  1552. chek = ((IList)lstName).Contains(name);
  1553. }
  1554. break;
  1555. default:
  1556. break;
  1557. }
  1558. CurrentLocation = -1;
  1559. return chek;
  1560. }
  1561. /// <summary>
  1562. /// 初始化
  1563. /// </summary>
  1564. public void NamingInitialization()
  1565. {
  1566. if (config.LstCustomTxt != null )
  1567. {
  1568. if (config.LstCustomTxt.customTxts1 != null && config.LstCustomTxt.customTxts1.Count > 0)
  1569. {
  1570. string[] lstName = config.LstCustomTxt.customTxts1.Select(a => a.customT).ToArray();
  1571. this.comboBox_T1.DataSource = lstName;
  1572. if (lstName.Length > 0) this.comboBox_T1.Text = config.Txt1;
  1573. }
  1574. else this.comboBox_T1.DataSource = null;
  1575. if (config.LstCustomTxt.customTxts2 != null && config.LstCustomTxt.customTxts2.Count > 0)
  1576. {
  1577. string[] lstName = config.LstCustomTxt.customTxts2.Select(a => a.customT).ToArray();
  1578. this.comboBox_T2.DataSource = lstName;
  1579. if (lstName.Length > 0) this.comboBox_T2.Text = config.Txt2;
  1580. }
  1581. else this.comboBox_T2.DataSource = null;
  1582. if (config.LstCustomTxt.customTxts3 != null && config.LstCustomTxt.customTxts3.Count > 0)
  1583. {
  1584. string[] lstName = config.LstCustomTxt.customTxts3.Select(a => a.customT).ToArray();
  1585. this.comboBox_T3.DataSource = lstName;
  1586. if (lstName.Length > 0) this.comboBox_T3.Text = config.Txt3;
  1587. }
  1588. else this.comboBox_T3.DataSource = null;
  1589. }
  1590. this.comboBox_T1.SelectedIndexChanged += new System.EventHandler(this.comboBox_T1_SelectedIndexChanged);
  1591. this.comboBox_T2.SelectedIndexChanged += new System.EventHandler(this.comboBox_T2_SelectedIndexChanged);
  1592. this.comboBox_T3.SelectedIndexChanged += new System.EventHandler(this.comboBox_T3_SelectedIndexChanged);
  1593. }
  1594. private void btn_DelT1_Click(object sender, EventArgs e)
  1595. {
  1596. if (comboBox_T1.Text.Trim() == "")
  1597. {
  1598. MessageBox.Show("参数不能为空!");
  1599. return;
  1600. };
  1601. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretcteddata.text") + "?", PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  1602. if (dr == DialogResult.Cancel) return;
  1603. CurrentLocation = 1;
  1604. if (config.LstCustomTxt == null || config.LstCustomTxt.customTxts1 == null || !Inspect())
  1605. {
  1606. MessageBox.Show("不存在此文本!");
  1607. return;
  1608. }
  1609. for (int i = 0; i < config.LstCustomTxt.customTxts1.Count; i++)
  1610. {
  1611. if (comboBox_T1.Text.Trim().Equals(config.LstCustomTxt.customTxts1[i].customT))
  1612. config.LstCustomTxt.customTxts1.Remove(config.LstCustomTxt.customTxts1[i]);
  1613. }
  1614. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
  1615. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  1616. if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  1617. MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
  1618. if (config.LstCustomTxt.customTxts1 != null && config.LstCustomTxt.customTxts1.Count > 0)
  1619. {
  1620. string[] lstName = config.LstCustomTxt.customTxts1.Select(a => a.customT).ToArray();
  1621. this.comboBox_T1.DataSource = lstName;
  1622. }
  1623. else this.comboBox_T1.DataSource = null;
  1624. }
  1625. private void btn_DelT2_Click(object sender, EventArgs e)
  1626. {
  1627. if (comboBox_T2.Text.Trim() == "")
  1628. {
  1629. MessageBox.Show("参数不能为空!");
  1630. return;
  1631. };
  1632. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretcteddata.text") + "?", PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  1633. if (dr == DialogResult.Cancel) return;
  1634. CurrentLocation = 2;
  1635. if (config.LstCustomTxt == null || config.LstCustomTxt.customTxts2 == null || !Inspect())
  1636. {
  1637. MessageBox.Show("不存在此文本!");
  1638. return;
  1639. }
  1640. for (int i = 0; i < config.LstCustomTxt.customTxts2.Count; i++)
  1641. {
  1642. if (comboBox_T2.Text.Trim().Equals(config.LstCustomTxt.customTxts2[i].customT))
  1643. config.LstCustomTxt.customTxts2.Remove(config.LstCustomTxt.customTxts2[i]);
  1644. }
  1645. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
  1646. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  1647. if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  1648. MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
  1649. if (config.LstCustomTxt.customTxts2 != null && config.LstCustomTxt.customTxts2.Count > 0)
  1650. {
  1651. string[] lstName = config.LstCustomTxt.customTxts2.Select(a => a.customT).ToArray();
  1652. this.comboBox_T2.DataSource = lstName;
  1653. }
  1654. else this.comboBox_T2.DataSource = null;
  1655. }
  1656. private void btn_DelT3_Click(object sender, EventArgs e)
  1657. {
  1658. if (comboBox_T3.Text.Trim() == "")
  1659. {
  1660. MessageBox.Show("参数不能为空!");
  1661. return;
  1662. };
  1663. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretcteddata.text") + "?", PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  1664. if (dr == DialogResult.Cancel) return;
  1665. CurrentLocation = 3;
  1666. if (config.LstCustomTxt == null || config.LstCustomTxt.customTxts3 == null || !Inspect())
  1667. {
  1668. MessageBox.Show("不存在此文本!");
  1669. return;
  1670. }
  1671. for (int i = 0; i < config.LstCustomTxt.customTxts3.Count; i++)
  1672. {
  1673. if (comboBox_T3.Text.Trim().Equals(config.LstCustomTxt.customTxts3[i].customT))
  1674. config.LstCustomTxt.customTxts3.Remove(config.LstCustomTxt.customTxts3[i]);
  1675. }
  1676. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
  1677. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  1678. if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  1679. MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
  1680. if (config.LstCustomTxt.customTxts3 != null && config.LstCustomTxt.customTxts3.Count > 0)
  1681. {
  1682. string[] lstName = config.LstCustomTxt.customTxts3.Select(a => a.customT).ToArray();
  1683. this.comboBox_T3.DataSource = lstName;
  1684. }
  1685. else this.comboBox_T3.DataSource = null;
  1686. }
  1687. /// <summary>
  1688. /// 鼠标事件-右键
  1689. /// </summary>
  1690. /// <param name="sender"></param>
  1691. /// <param name="e"></param>
  1692. private void listView1_MouseClick(object sender, MouseEventArgs e)
  1693. {
  1694. ListView listView = (ListView)sender;
  1695. ListViewItem item = listView.GetItemAt(e.X, e.Y);
  1696. if (item != null && e.Button == MouseButtons.Right)
  1697. {
  1698. this.contextMenuStrip1.Show(listView, e.X, e.Y);
  1699. }
  1700. }
  1701. /// <summary>
  1702. /// 右键保存
  1703. /// </summary>
  1704. /// <param name="sender"></param>
  1705. /// <param name="e"></param>
  1706. private void toolStripMenuItem1_Click(object sender, EventArgs e)
  1707. {
  1708. if (AppWorkspace.ActiveDocumentWorkspace != null)
  1709. {
  1710. if (AppWorkspace.startScriptRecording)
  1711. {
  1712. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  1713. }
  1714. AppWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
  1715. AppWorkspace.ActiveDocumentWorkspace.DoSaveNew();
  1716. }
  1717. InitData();
  1718. }
  1719. /// <summary>
  1720. /// 右键另存
  1721. /// </summary>
  1722. /// <param name="sender"></param>
  1723. /// <param name="e"></param>
  1724. private void toolStripMenuItem2_Click(object sender, EventArgs e)
  1725. {
  1726. if (AppWorkspace.ActiveDocumentWorkspace != null)
  1727. {
  1728. if (AppWorkspace.startScriptRecording)
  1729. {
  1730. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  1731. }
  1732. AppWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
  1733. AppWorkspace.ActiveDocumentWorkspace.DoSaveAsNew();
  1734. }
  1735. InitData();
  1736. }
  1737. /// <summary>
  1738. /// 右键强制关闭
  1739. /// </summary>
  1740. /// <param name="sender"></param>
  1741. /// <param name="e"></param>
  1742. private void toolStripMenuItem3_Click(object sender, EventArgs e)
  1743. {
  1744. if (this.AppWorkspace.DocumentWorkspaces.Length > 0 && this.AppWorkspace.ActiveDocumentWorkspace != null)
  1745. {
  1746. if (AppWorkspace.startScriptRecording)
  1747. {
  1748. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  1749. }
  1750. this.AppWorkspace.ActiveDocumentWorkspace.Document.Dirty = false;
  1751. this.AppWorkspace.PerformAction(new CloseWorkspaceAction());
  1752. }
  1753. InitData();
  1754. }
  1755. private Bitmap copyedBitmap;//复制的图片
  1756. private int nameNum = 0;//命名使用
  1757. /// <summary>
  1758. /// 右键复制图片
  1759. /// </summary>
  1760. /// <param name="sender"></param>
  1761. /// <param name="e"></param>
  1762. private void toolStripMenuItem4_Click(object sender, EventArgs e)
  1763. {
  1764. if (AppWorkspace.ActiveDocumentWorkspace != null && AppWorkspace.ActiveDocumentWorkspace.CompositionSurface != null)
  1765. {
  1766. if (AppWorkspace.startScriptRecording)
  1767. {
  1768. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  1769. }
  1770. Bitmap temp = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap();
  1771. copyedBitmap = new Bitmap(temp.Width, temp.Height);
  1772. Graphics graphics = Graphics.FromImage(copyedBitmap);
  1773. graphics.DrawImage(temp, 0, 0, temp.Width, temp.Height);
  1774. if (AppWorkspace.ActiveDocumentWorkspace.GraphicsList.IsExsitSpecificObject(DrawToolType.ImageCut))
  1775. {
  1776. //获取裁剪的矩形区域
  1777. List<DrawObject> objList = AppWorkspace.ActiveDocumentWorkspace.GraphicsList.GetDrawToolTypeList(DrawToolType.ImageCut);
  1778. ImageCutDraw imageCutDraw = (ImageCutDraw)objList[0];
  1779. RectangleF cutRectangle = imageCutDraw.Rectangle;
  1780. copyedBitmap = DrawRulerHelper.KiCut(copyedBitmap, (int)cutRectangle.X, (int)cutRectangle.Y, (int)cutRectangle.Width, (int)cutRectangle.Height);
  1781. }
  1782. }
  1783. if (copyedBitmap != null)
  1784. {
  1785. if (AppWorkspace.startScriptRecording)
  1786. {
  1787. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  1788. }
  1789. DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
  1790. Document document = Document.FromImageMat(Camera.Tools.ToMat(copyedBitmap));
  1791. dw.Document = document;
  1792. //图片命名
  1793. nameNum++;
  1794. int numLength = nameNum.ToString().Length;
  1795. string joinName = "";
  1796. switch (numLength)
  1797. {
  1798. case 1:
  1799. joinName = "00" + nameNum;
  1800. break;
  1801. case 2:
  1802. joinName = "0" + nameNum;
  1803. break;
  1804. default:
  1805. joinName = nameNum.ToString();
  1806. break;
  1807. }
  1808. dw.xmlSaveModel = AppWorkspace.ActiveDocumentWorkspace.xmlSaveModel;
  1809. dw.rules = AppWorkspace.ActiveDocumentWorkspace.rules;
  1810. dw.fileText = PdnResources.GetString("Menu.Copythepicture.Text") + "-" + joinName;
  1811. AppWorkspace.ActiveDocumentWorkspace = dw;
  1812. }
  1813. InitData();
  1814. }
  1815. private void SplitContainerSize()
  1816. {
  1817. splitContainer1.Size = new Size(800, 450);
  1818. }
  1819. private void comboBox_T1_SelectedIndexChanged(object sender, EventArgs e)
  1820. {
  1821. TxtAssignment();
  1822. PreviewRefresh(config.CaptureSaveMode);
  1823. }
  1824. private void comboBox_T2_SelectedIndexChanged(object sender, EventArgs e)
  1825. {
  1826. TxtAssignment();
  1827. PreviewRefresh(config.CaptureSaveMode);
  1828. }
  1829. private void comboBox_T3_SelectedIndexChanged(object sender, EventArgs e)
  1830. {
  1831. TxtAssignment();
  1832. PreviewRefresh(config.CaptureSaveMode);
  1833. }
  1834. private void comboBox_Name_SelectedIndexChanged(object sender, EventArgs e)
  1835. {
  1836. if (comboBox_Name.Text.Trim() == "")
  1837. {
  1838. MessageBox.Show("参数不能为空!");
  1839. return;
  1840. }
  1841. config.CurrentName = comboBox_Name.Text.Trim();
  1842. comboBox_Name_SelectedIndex();
  1843. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
  1844. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  1845. if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  1846. MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
  1847. PreviewRefresh(config.CaptureSaveMode);
  1848. }
  1849. private void comboBox_Name_SelectedIndex()
  1850. {
  1851. string CurrentName = config.CurrentName;
  1852. if (config.LstNaming.Count > 0)
  1853. {
  1854. foreach (NamingMethod item in config.LstNaming)
  1855. {
  1856. if (CurrentName.Equals(item.name))
  1857. {
  1858. config.NamePrefix = item.NamePrefix;
  1859. config.NameFormat = item.NameFormat;
  1860. config.NumberNum = item.NumberNum;
  1861. config.NameStatus = item.NameStatus;
  1862. config.ContinueNum = item.ContinueNum;
  1863. }
  1864. }
  1865. }
  1866. }
  1867. CreateNameDialog dialog;
  1868. public string imgType = string.Empty;
  1869. private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
  1870. {
  1871. string imgName = this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].GetFriendlyName();
  1872. int index = 0;
  1873. if (imgName.Contains('.'))
  1874. {
  1875. index = imgName.LastIndexOf('.');
  1876. imgType = imgName.Substring(index);
  1877. //从下一个索引开始截取
  1878. imgName = imgName.Substring(0, index);
  1879. }
  1880. else
  1881. {
  1882. imgType = "";
  1883. }
  1884. dialog = new CreateNameDialog(this);
  1885. dialog.Text = "重命名";
  1886. dialog.StartPosition = FormStartPosition.CenterParent;
  1887. dialog.SetTextBoxValue(imgName);
  1888. dialog.textBox1.MaxLength = 999;
  1889. dialog.ShowDialog();
  1890. }
  1891. /// <summary>
  1892. /// 新建文件夹的结果函数
  1893. /// </summary>
  1894. /// <param name="name"></param>
  1895. public override void GetCreateName(string name)
  1896. {
  1897. DocumentWorkspace iDocumentWorkspace = AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index];
  1898. string imgName = iDocumentWorkspace.GetFriendlyName();
  1899. int index = 0;
  1900. if (imgName.Contains('.'))
  1901. {
  1902. index = imgName.LastIndexOf('.');
  1903. imgName = imgName.Substring(0, index);
  1904. }
  1905. //获取图片路径
  1906. string fileName;
  1907. //FileType fileType;
  1908. //SaveConfigToken saveConfigToken;
  1909. iDocumentWorkspace.GetDocumentSaveOptions(out fileName/*, out fileType, out saveConfigToken*/);
  1910. string path = Path.GetDirectoryName(fileName);
  1911. string filePath = path == null? "" : path + "\\" + name + imgType;
  1912. string xmlName = path == null ? "" : path + "\\" + imgName + ".xml";
  1913. string xmlPath = path == null ? "" : path + "\\" + name + ".xml";
  1914. if (System.IO.File.Exists(fileName)) System.IO.File.Move(fileName, filePath);//更改图片名称
  1915. if (System.IO.File.Exists(xmlName)) System.IO.File.Move(xmlName, xmlPath);//更改xml文件名称
  1916. this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].fileText = name + imgType;
  1917. this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].UpdateDw2buttonName(name + imgType);
  1918. if (path != null)
  1919. {
  1920. this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].picName = name + imgType;
  1921. this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].filePath = filePath;
  1922. this.listView1.Items[this.listView1.FocusedItem.Index].Text = name + imgType;
  1923. }
  1924. this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].Refresh();
  1925. this.listView1.Items[this.listView1.FocusedItem.Index].Name = name + imgType;
  1926. //InitData();
  1927. dialog.Close();
  1928. }
  1929. private void ImageIndexDialog_FormClosing(object sender, FormClosingEventArgs e)
  1930. {
  1931. this.AppWorkspace.toolBar.RefreshBtnSelect(false, "ImageIndex");
  1932. this.AppWorkspace.toolsPanel.RefreshBtnSelect(false, "ImageIndex");
  1933. config.Txt1 = comboBox_T1.Text;
  1934. config.Txt2 = comboBox_T2.Text;
  1935. config.Txt3 = comboBox_T2.Text;
  1936. }
  1937. }
  1938. }