ImageIndexDialog.cs 96 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087
  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.AutoSize = 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(65, 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 bitmap;
  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. //
  580. // dialog
  581. //
  582. this.StartPosition = FormStartPosition.CenterScreen;
  583. this.Text = PdnResources.GetString("Menu.Tools.ImageIndex.Text");
  584. //
  585. // 设置listview事件
  586. //
  587. this.listView1.SelectedIndexChanged += new EventHandler(ListViewSelectedIndexChanged);
  588. comboBox_Name_Refresh();
  589. NamingInitialization();
  590. //
  591. // 初始化数据
  592. //
  593. this.InitData();
  594. this.listView1.View = View.LargeIcon;
  595. //PreviewRefresh();
  596. //SplitContainerSize();
  597. }
  598. //初始化折叠与展开初始值
  599. private void CollapseUnfold()
  600. {
  601. this.fromMinSize = splitContainer1.Panel1.Width;
  602. this.fromMaxSize = this.Width;
  603. if (btn_Hide.Text == "<<")
  604. this.MaximumSize = new Size(0, 0);
  605. else
  606. this.MaximumSize = new Size(400, Screen.PrimaryScreen.Bounds.Height);
  607. this.groupBox1.MaximumSize = new Size(366, Screen.PrimaryScreen.Bounds.Height);
  608. }
  609. private void InitializeButtonBackgroudImage()
  610. {
  611. this.button7.FlatStyle = FlatStyle.Flat;
  612. this.button7.FlatAppearance.BorderSize = 0;
  613. this.button7.BackgroundImageLayout = ImageLayout.Center;
  614. this.button7.BackgroundImage = PdnResources.GetImageResource("Icons.ProjectEngineering.ListMode.png").Reference;
  615. this.button8.FlatStyle = FlatStyle.Flat;
  616. this.button8.FlatAppearance.BorderSize = 0;
  617. this.button8.BackgroundImageLayout = ImageLayout.Center;
  618. this.button8.BackgroundImage = PdnResources.GetImageResource("Icons.ProjectEngineering.PicMode.png").Reference;
  619. this.button10.FlatStyle = FlatStyle.Flat;
  620. this.button10.FlatAppearance.BorderSize = 0;
  621. this.button10.BackgroundImageLayout = ImageLayout.Center;
  622. this.button10.BackgroundImage = PdnResources.GetImageResource("Icons.MenuFileBulkSaveIcon.png").Reference;
  623. this.toolStripMenuItem1.Image = PdnResources.GetImageResource("Icons.MenuFileSaveIcon.png").Reference;
  624. this.toolStripMenuItem2.Image = PdnResources.GetImageResource("Icons.MenuFileSaveAsIcon.png").Reference;
  625. this.toolStripMenuItem3.Image = PdnResources.GetImageResource("Icons.MenuFileCloseIcon.png").Reference;
  626. this.toolStripMenuItem4.Image = PdnResources.GetImageResource("Icons.MenuEditCopyIcon.png").Reference;
  627. }
  628. /// <summary>
  629. /// 初始化提示信息及按钮事件
  630. /// </summary>
  631. private void InitializeToolTipAndEvent()
  632. {
  633. this.toolTip1 = new ToolTip();
  634. this.toolTip1.SetToolTip(this.button7, PdnResources.GetString("Menu.tool.Templatemanent.Listmode.text"));
  635. this.toolTip1.SetToolTip(this.button8, PdnResources.GetString("Menu.tool.Templategement.Thumbnailmode.text"));
  636. this.toolTip1.SetToolTip(this.button10, "批量保存");
  637. this.toolTip1.SetToolTip(this.btn_Hide, "折叠&展开");
  638. this.toolTip1.ShowAlways = true;
  639. }
  640. /// <summary>
  641. /// ListView选择事件
  642. /// </summary>
  643. /// <param name="sender"></param>
  644. /// <param name="e"></param>
  645. private void ListViewSelectedIndexChanged(object sender, EventArgs e)
  646. {
  647. if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Selected)
  648. {
  649. if (AppWorkspace.toInitImageIndexDialogFlag == -1)
  650. {
  651. AppWorkspace.toInitImageIndexDialogFlag = 2;
  652. AppWorkspace.ActiveDocumentWorkspace = AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index];
  653. }
  654. this.bitmap = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap();
  655. isFirst = true;
  656. lastPoint.X = 0;
  657. lastPoint.Y = 0;
  658. refreshSizeMode();
  659. }
  660. }
  661. /// <summary>
  662. /// 初始化图片列表数据
  663. /// </summary>
  664. public void InitData()
  665. {
  666. this.imageList1.Images.Clear();
  667. this.listView1.Items.Clear();
  668. this.listView1.Columns.Clear();
  669. //this.pictureBox1.Image = null;
  670. if (AppWorkspace.DocumentWorkspaces.Length == 0 || AppWorkspace.ActiveDocumentWorkspace == null)
  671. {
  672. this.listView1.Refresh();
  673. this.pictureBox1.Image = null;
  674. return;
  675. }
  676. int typeLenth = 70;
  677. int nameLenth = 100;
  678. if (this.listView1.Width > 310)
  679. {
  680. typeLenth = this.listView1.Width / 5;
  681. nameLenth = this.listView1.Width * 2 / 5;
  682. if (typeLenth > 70)
  683. {
  684. typeLenth = 70;
  685. nameLenth = this.listView1.Width - 215;
  686. }
  687. }
  688. ColumnHeader header = new ColumnHeader();
  689. header.Text = PdnResources.GetString("Menu.File.Text");
  690. header.Width = nameLenth;
  691. this.listView1.Columns.Add(header);
  692. header = new ColumnHeader();
  693. header.Text = PdnResources.GetString("Menu.Type.text");
  694. header.Width = typeLenth;
  695. this.listView1.Columns.Add(header);
  696. header = new ColumnHeader();
  697. header.Text = PdnResources.GetString("Menu.size.text");
  698. header.Width = typeLenth;
  699. this.listView1.Columns.Add(header);
  700. header = new ColumnHeader();
  701. header.Text = PdnResources.GetString("MeasurementUnit.Pixel");
  702. header.Width = typeLenth;
  703. this.listView1.Columns.Add(header);
  704. 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);
  705. //初始化图片列表
  706. for (int i = 0; i < AppWorkspace.DocumentWorkspaces.Length; i++)
  707. {
  708. DocumentWorkspace iDocumentWorkspace = AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - i];
  709. this.imageList1.Images.Add("img" + i, iDocumentWorkspace.CompositionSurface.Thumborigin);
  710. this.listView1.Items.Add("", i);
  711. this.listView1.Items[i].ImageIndex = i;
  712. this.listView1.Items[i].Text = iDocumentWorkspace.GetFriendlyName();
  713. this.listView1.Items[i].Name = iDocumentWorkspace.GetFriendlyName();
  714. string type = "";
  715. if (iDocumentWorkspace.GetFriendlyName().IndexOf('.') > -1)
  716. {
  717. type = iDocumentWorkspace.GetFriendlyName().Substring(iDocumentWorkspace.GetFriendlyName().LastIndexOf('.') + 1, iDocumentWorkspace.GetFriendlyName().Length - iDocumentWorkspace.GetFriendlyName().LastIndexOf('.') - 1);
  718. }
  719. else
  720. {
  721. type = "";
  722. }
  723. this.bitmap = iDocumentWorkspace.CompositionSurface.CreateAliasedBitmap();
  724. //图片类型
  725. this.listView1.Items[i].SubItems.Add(type);
  726. //获取图片路径
  727. string fileName;
  728. FileType fileType;
  729. SaveConfigToken saveConfigToken;
  730. iDocumentWorkspace.GetDocumentSaveOptions(out fileName, out fileType, out saveConfigToken);
  731. //获取图片信息
  732. if (fileName != null)
  733. {
  734. //获取图片对应xml
  735. PicConfigModel configModel = null;
  736. try
  737. {
  738. string path = Path.GetDirectoryName(fileName);
  739. string xmlPath = path + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".xml";
  740. //如果xml存在
  741. if (System.IO.File.Exists(xmlPath))
  742. {
  743. configModel = XmlSerializeHelper.DESerializer<PicConfigModel>(FileOperationHelper.ReadStringFromFile(xmlPath, FileMode.Open));
  744. if (configModel != null)
  745. {
  746. //图片大小
  747. this.listView1.Items[i].SubItems.Add(configModel.meta.imageSize);
  748. }
  749. }
  750. else
  751. {
  752. //获取图片信息
  753. if (System.IO.File.Exists(fileName))
  754. {
  755. FileInfo fi = new FileInfo(fileName);
  756. //图片大小
  757. this.listView1.Items[i].SubItems.Add(FileOperationHelper.GetLength(fi.Length));
  758. }
  759. }
  760. }
  761. catch (Exception)
  762. {
  763. }
  764. }
  765. else
  766. {
  767. //图像若没有信息像素计算
  768. double length = bitmap.Width * bitmap.Height;
  769. double lengthKb = length * 24 /8 / 1024 / 4.77;
  770. double lengthMb = length * 24/ 8 / 1024 / 1024 / 4.77;
  771. if (lengthKb >= 1024)
  772. {
  773. this.listView1.Items[i].SubItems.Add(lengthMb.ToString("f2") + "M");
  774. }
  775. else
  776. {
  777. this.listView1.Items[i].SubItems.Add(lengthKb.ToString("f0") + "KB");
  778. }
  779. }
  780. //图片像素
  781. this.listView1.Items[i].SubItems.Add(bitmap.Width.ToString() + "*" + bitmap.Height.ToString());
  782. }
  783. if (index != -1)
  784. {
  785. this.listView1.Items[index].Focused = true;
  786. this.listView1.Items[index].Selected = true;
  787. }
  788. else
  789. {
  790. if (this.listView1.Items.Count > 0 && AppWorkspace.DocumentWorkspaces.Length > 0 && AppWorkspace.ActiveDocumentWorkspace != null)
  791. {
  792. this.listView1.Items[0].Focused = true;
  793. this.listView1.Items[0].Selected = true;
  794. }
  795. }
  796. }
  797. /// <summary>
  798. /// 根据图片尺寸判断picturebox的显示模式并刷新图片
  799. /// </summary>
  800. private void refreshSizeMode()
  801. {
  802. if (bitmap != null)
  803. {
  804. if (bitmap.Width > pictureBox1.Size.Width || bitmap.Height > pictureBox1.Size.Height)
  805. {
  806. pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
  807. }
  808. else
  809. {
  810. pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
  811. }
  812. this.pictureBox1.Image = bitmap;
  813. }
  814. }
  815. /// <summary>
  816. /// 窗体尺寸改变
  817. /// </summary>
  818. /// <param name="sender"></param>
  819. /// <param name="e"></param>
  820. private void ImageIndexDialog_Resize(object sender, EventArgs e)
  821. {
  822. lastPoint.X = 0;
  823. lastPoint.Y = 0;
  824. isFirst = true;
  825. refreshSizeMode();
  826. }
  827. /// <summary>
  828. /// 绘制picturebox
  829. /// </summary>
  830. /// <param name="sender"></param>
  831. /// <param name="e"></param>
  832. private void pictureBox1_Paint(object sender, PaintEventArgs e)
  833. {
  834. if (this.pictureBox1.Image != null)
  835. {
  836. if (isFirst)
  837. {
  838. //获取缩略图对应矩形
  839. PropertyInfo _ImageRectanglePropert = this.pictureBox1.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic);
  840. imageRect = (Rectangle)_ImageRectanglePropert.GetValue(this.pictureBox1, null);
  841. Size size = AppWorkspace.ActiveDocumentWorkspace.panel.ClientSize;//document窗体尺寸
  842. double ratio = AppWorkspace.ActiveDocumentWorkspace.ScaleRatio;
  843. if (size.Width < this.bitmap.Width * ratio)
  844. widthRatio = size.Width / (this.bitmap.Width * ratio);
  845. else
  846. widthRatio = 1;
  847. if (size.Height < this.bitmap.Height * ratio)
  848. heightRatio = size.Height / (this.bitmap.Height * ratio);
  849. else
  850. heightRatio = 1;
  851. Point scPoint = AppWorkspace.ActiveDocumentWorkspace.PanelScrollPosition;//当前滚动条位置
  852. scRatioWidth = imageRect.Width / (bitmap.Width * ratio);
  853. scRatioHeight = imageRect.Height / (bitmap.Height * ratio);
  854. //缩略图中红框选中区域
  855. zoomRect = new Rectangle(imageRect.X + (int)(scPoint.X * scRatioWidth), imageRect.Y + (int)(scPoint.Y * scRatioHeight),
  856. (int)(imageRect.Width * widthRatio), (int)(imageRect.Height * heightRatio));
  857. //红框矩形的最小尺寸,即原图放大3200%
  858. double minWidthRatio = size.Width / (this.bitmap.Width * 32d);
  859. double minHeightRatio = size.Height / (this.bitmap.Height * 32d);
  860. minRectWidth = (int)(Math.Round(imageRect.Width * minWidthRatio));
  861. minRectHeight = (int)(Math.Round(imageRect.Height * minHeightRatio));
  862. }
  863. e.Graphics.DrawRectangle(new Pen(Color.Red), zoomRect.X, zoomRect.Y, zoomRect.Width - 1, zoomRect.Height - 1);
  864. e.Graphics.FillRectangle(new SolidBrush(Color.Black), new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 9, 9));
  865. }
  866. }
  867. /// <summary>
  868. /// picturebox的鼠标按下事件
  869. /// </summary>
  870. /// <param name="sender"></param>
  871. /// <param name="e"></param>
  872. private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
  873. {
  874. lastPoint.X = e.X;
  875. lastPoint.Y = e.Y;
  876. //是否平移
  877. if (zoomRect.Contains(e.Location) && !new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 9, 9).Contains(e.Location))
  878. isMoved = true;
  879. else
  880. isMoved = false;
  881. //是否放大缩小
  882. if (new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 9, 9).Contains(e.Location))
  883. isResized = true;
  884. else
  885. isResized = false;
  886. }
  887. /// <summary>
  888. /// pocturebox的鼠标移动事件
  889. /// </summary>
  890. /// <param name="sender"></param>
  891. /// <param name="e"></param>
  892. private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
  893. {
  894. //修改鼠标形状
  895. this.pictureBox1.Cursor = Cursors.Default;
  896. if (zoomRect != null)
  897. {
  898. if (zoomRect.Contains(e.Location) && !new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 9, 9).Contains(e.Location))
  899. {
  900. this.pictureBox1.Cursor = Cursors.SizeAll;
  901. }
  902. if (new Rectangle(zoomRect.Right - 4, zoomRect.Bottom - 4, 7, 7).Contains(e.Location))
  903. {
  904. this.pictureBox1.Cursor = Cursors.SizeNWSE;
  905. }
  906. }
  907. if (e.Button != MouseButtons.Left)
  908. return;
  909. //拖拽
  910. if (zoomRect != null && isMoved)
  911. {
  912. isFirst = false;
  913. Point p = e.Location;
  914. int dx = p.X - lastPoint.X;
  915. int dy = p.Y - lastPoint.Y;
  916. lastPoint.X = p.X;
  917. lastPoint.Y = p.Y;
  918. zoomRect.X += dx;
  919. zoomRect.Y += dy;
  920. //控制矩形框不超过缩略图尺寸
  921. int xc = (this.pictureBox1.Width - this.imageRect.Width) / 2;
  922. int yc = (this.pictureBox1.Height - this.imageRect.Height) / 2;
  923. if (zoomRect.X < xc) zoomRect.X = xc;
  924. if (zoomRect.Y < yc) zoomRect.Y = yc;
  925. if (zoomRect.X + zoomRect.Width > imageRect.Width + xc) zoomRect.X = imageRect.Width - zoomRect.Width + xc;
  926. if (zoomRect.Y + zoomRect.Height > imageRect.Height + yc) zoomRect.Y = imageRect.Height - zoomRect.Height + yc;
  927. this.pictureBox1.Refresh();
  928. //修改document的滚动条
  929. Point scPoint = AppWorkspace.ActiveDocumentWorkspace.PanelScrollPosition;
  930. double scrollDx = dx / scRatioWidth;
  931. double scrollDy = dy / scRatioHeight;
  932. Point newScPoint = new Point(scPoint.X + Convert.ToInt32(Math.Round(scrollDx)), scPoint.Y + Convert.ToInt32(Math.Round(scrollDy)));
  933. AppWorkspace.ActiveDocumentWorkspace.PanelScrollPosition = newScPoint;
  934. }
  935. //缩放
  936. if (zoomRect != null && isResized)
  937. {
  938. isFirst = false;
  939. Point p = e.Location;
  940. int dx = p.X - lastPoint.X;
  941. int dy = p.Y - lastPoint.Y;
  942. lastPoint.X = p.X;
  943. lastPoint.Y = p.Y;
  944. //偏移量取横坐标与纵坐标中绝对值大的
  945. int delta = dx;
  946. if (Math.Abs(dy) > Math.Abs(dx))
  947. delta = dy;
  948. Size size = AppWorkspace.ActiveDocumentWorkspace.panel.ClientSize;//document尺寸
  949. double ratio = AppWorkspace.ActiveDocumentWorkspace.ScaleRatio;//缩放比
  950. //图片缩放后的宽和高都小于document窗口尺寸
  951. if (size.Width > this.bitmap.Width * ratio && size.Height > this.bitmap.Height * ratio)
  952. {
  953. AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;//修改缩放模式
  954. //只修改缩放比,不改变缩略图矩形框尺寸
  955. ratio += (-delta / 100d);
  956. ratio = GetMinRatio(ratio);
  957. RefreshActiveDocumentScaleFactor(ratio);
  958. }
  959. //图片缩放后的宽和高大于等于doucment窗口尺寸
  960. else
  961. {
  962. double aspectRatio = size.Width / (size.Height * 1d);//宽高比
  963. int maxResizedWidth = imageRect.Right - zoomRect.Right;//正向最大拖动宽度
  964. int maxResizedHeigth = imageRect.Bottom - zoomRect.Bottom;//正向最大拖动高度
  965. int maxRectWidth = maxResizedWidth + zoomRect.Width;//小矩形可放大到的最大宽度
  966. int maxRectHeight = maxResizedHeigth + zoomRect.Height;//小矩形可放大到的最大高度
  967. double newScaleRatio = 0;//计算后新的缩放比
  968. double newScPointX = 0;//计算后新的滚动条横坐标
  969. double newScPointY = 0;//计算后新的滚动条纵坐标
  970. //图片缩放后只有宽小于ducument窗口尺寸
  971. if (size.Width > this.bitmap.Width * ratio && size.Height <= this.bitmap.Height * ratio)
  972. {
  973. int minHeight = (int)Math.Round(imageRect.Width / aspectRatio);//矩形框可拖动的最小高度
  974. zoomRect.Height += delta;
  975. if (zoomRect.Height > maxRectHeight)
  976. {
  977. zoomRect.Height = maxRectHeight;
  978. //矩形框的起始点不在缩略图的起始点上时,高度达到默认可变的最大值后,同时修改纵坐标和高度
  979. if (maxRectHeight < imageRect.Height)
  980. {
  981. zoomRect.Y -= delta;
  982. if (zoomRect.Y < imageRect.Y)
  983. zoomRect.Y = imageRect.Y;
  984. zoomRect.Height += delta;
  985. if (zoomRect.Height > imageRect.Height)
  986. zoomRect.Height = imageRect.Height;
  987. this.pictureBox1.Refresh();
  988. newScaleRatio = Math.Round(size.Height / heightRatio / this.bitmap.Height, 2);//重新计算缩放比
  989. newScaleRatio = GetMinRatio(newScaleRatio);
  990. //重新计算滚轮所需比例
  991. scRatioWidth = imageRect.Width / (bitmap.Width * newScaleRatio);
  992. scRatioHeight = imageRect.Height / (bitmap.Height * newScaleRatio);
  993. //重新计算document的滚动条横坐标与纵坐标
  994. newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
  995. newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
  996. RefreshActiveDocumentScaleFactorAndScroll(ratio, new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY)));
  997. return;
  998. }
  999. //高度达到极限,只改变缩放比
  1000. this.pictureBox1.Refresh();
  1001. ratio += (-delta / 100d);
  1002. ratio = GetMinRatio(ratio);
  1003. RefreshActiveDocumentScaleFactor(ratio);
  1004. return;
  1005. }
  1006. if (zoomRect.Height < minHeight)
  1007. zoomRect.Height = minHeight;
  1008. this.pictureBox1.Refresh();
  1009. heightRatio = zoomRect.Height / (imageRect.Height * 1d);
  1010. heightRatio = GetMaxDocumentWithBitmapRatio(heightRatio);
  1011. newScaleRatio = Math.Round(size.Height / heightRatio / this.bitmap.Height, 2);//重新计算缩放比
  1012. }
  1013. //图片缩放后只有高小于ducument窗口尺寸
  1014. if (size.Width <= this.bitmap.Width * ratio && size.Height > this.bitmap.Height * ratio)
  1015. {
  1016. int minWidth = (int)Math.Round(imageRect.Height * aspectRatio);//矩形框可拖动的最小宽度
  1017. zoomRect.Width += delta;
  1018. if (zoomRect.Width > maxRectWidth)
  1019. {
  1020. zoomRect.Width = maxRectWidth;
  1021. //矩形框的起始点不在缩略图的起始点上时,宽度达到默认可变的最大值后,同时修改横坐标和宽度
  1022. if (maxRectWidth < imageRect.Width)
  1023. {
  1024. zoomRect.X -= delta;
  1025. if (zoomRect.X < imageRect.X)
  1026. zoomRect.X = imageRect.X;
  1027. zoomRect.Width += delta;
  1028. if (zoomRect.Width > imageRect.Width)
  1029. zoomRect.Width = imageRect.Width;
  1030. this.pictureBox1.Refresh();
  1031. newScaleRatio = Math.Round(size.Width / widthRatio / this.bitmap.Width, 2);//重新计算缩放比
  1032. newScaleRatio = GetMinRatio(newScaleRatio);
  1033. //重新计算滚轮所需比例
  1034. scRatioWidth = imageRect.Width / (bitmap.Width * newScaleRatio);
  1035. scRatioHeight = imageRect.Height / (bitmap.Height * newScaleRatio);
  1036. //重新计算document的滚动条横坐标与纵坐标
  1037. newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
  1038. newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
  1039. RefreshActiveDocumentScaleFactorAndScroll(newScaleRatio, new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY)));
  1040. return;
  1041. }
  1042. //宽度达到极限,改变缩放比
  1043. this.pictureBox1.Refresh();
  1044. ratio += (-delta / 100d);
  1045. ratio = GetMinRatio(ratio);
  1046. RefreshActiveDocumentScaleFactor(ratio);
  1047. return;
  1048. }
  1049. if (zoomRect.Width < minWidth)
  1050. zoomRect.Width = minWidth;
  1051. this.pictureBox1.Refresh();
  1052. widthRatio = zoomRect.Width / (imageRect.Width * 1d);
  1053. widthRatio = GetMaxDocumentWithBitmapRatio(widthRatio);
  1054. newScaleRatio = Math.Round(size.Width / widthRatio / this.bitmap.Width, 2);//重新计算缩放比
  1055. }
  1056. //图片缩放后的宽和高都不小于document窗体尺寸
  1057. if (size.Width <= this.bitmap.Width * ratio && size.Height <= this.bitmap.Height * ratio)
  1058. {
  1059. if (maxResizedWidth < maxResizedHeigth)
  1060. {
  1061. zoomRect.Width += delta;
  1062. if (zoomRect.Width > maxRectWidth)
  1063. {
  1064. zoomRect.Width = maxRectWidth;
  1065. //矩形框的宽度与缩略图宽度相同时才可改变高度并调整缩放比
  1066. if(zoomRect.Width >= imageRect.Width)
  1067. {
  1068. zoomRect.Height += delta;
  1069. this.pictureBox1.Refresh();
  1070. heightRatio = zoomRect.Height / (imageRect.Height * 1d);
  1071. heightRatio = GetMaxDocumentWithBitmapRatio(heightRatio);
  1072. newScaleRatio = Math.Round(size.Height / heightRatio / this.bitmap.Height, 2);//重新计算缩放比
  1073. newScaleRatio = GetMinRatio(newScaleRatio);
  1074. //重新计算滚轮所需比例
  1075. scRatioWidth = imageRect.Width / (bitmap.Width * newScaleRatio);
  1076. scRatioHeight = imageRect.Height / (bitmap.Height * newScaleRatio);
  1077. //重新计算document的滚动条横坐标与纵坐标
  1078. newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
  1079. newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
  1080. RefreshActiveDocumentScaleFactorAndScroll(newScaleRatio, new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY)));
  1081. return;
  1082. }
  1083. }
  1084. if (zoomRect.Width < minRectWidth)
  1085. zoomRect.Width = minRectWidth;
  1086. zoomRect.Height = (int)Math.Round(zoomRect.Width / aspectRatio);
  1087. }
  1088. else
  1089. {
  1090. zoomRect.Height += delta;
  1091. if (zoomRect.Height > maxRectHeight)
  1092. {
  1093. zoomRect.Height = maxRectHeight;
  1094. //矩形框的高度与缩略图高度相同时才可改变宽度并调整缩放比
  1095. if (zoomRect.Height >= imageRect.Height)
  1096. {
  1097. zoomRect.Width += delta;
  1098. this.pictureBox1.Refresh();
  1099. widthRatio = zoomRect.Width / (imageRect.Width * 1d);
  1100. widthRatio = GetMaxDocumentWithBitmapRatio(widthRatio);
  1101. newScaleRatio = Math.Round(size.Width / widthRatio / this.bitmap.Width, 2);//重新计算缩放比
  1102. newScaleRatio = GetMinRatio(newScaleRatio);
  1103. //重新计算滚轮所需比例
  1104. scRatioWidth = imageRect.Width / (bitmap.Width * newScaleRatio);
  1105. scRatioHeight = imageRect.Height / (bitmap.Height * newScaleRatio);
  1106. //重新计算document的滚动条横坐标与纵坐标
  1107. newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
  1108. newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
  1109. RefreshActiveDocumentScaleFactorAndScroll(newScaleRatio, new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY)));
  1110. return;
  1111. }
  1112. }
  1113. if (zoomRect.Height < minRectHeight)
  1114. zoomRect.Height = minRectHeight;
  1115. zoomRect.Width = (int)Math.Round(zoomRect.Height * aspectRatio);
  1116. }
  1117. this.pictureBox1.Refresh();
  1118. //重新计算比例
  1119. widthRatio = zoomRect.Width / (imageRect.Width * 1d);
  1120. widthRatio = GetMaxDocumentWithBitmapRatio(widthRatio);
  1121. heightRatio = zoomRect.Height / (imageRect.Height * 1d);
  1122. heightRatio = GetMaxDocumentWithBitmapRatio(heightRatio);
  1123. //计算document的缩放比,宽和高的计算结果会有细微差异
  1124. double scaleW = Math.Round(size.Width / widthRatio / this.bitmap.Width, 2);
  1125. double scaleH = Math.Round(size.Height / heightRatio / this.bitmap.Height, 2);
  1126. //取大的值作为新的缩放比?不确定
  1127. if (scaleW >= scaleH)
  1128. newScaleRatio = scaleW;
  1129. else
  1130. newScaleRatio = scaleH;
  1131. }
  1132. //重新计算滚轮所需比例
  1133. scRatioWidth = imageRect.Width / (bitmap.Width * newScaleRatio);
  1134. scRatioHeight = imageRect.Height / (bitmap.Height * newScaleRatio);
  1135. //重新计算document的滚动条横坐标与纵坐标
  1136. newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
  1137. newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
  1138. RefreshActiveDocumentScaleFactorAndScroll(newScaleRatio, new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY)));
  1139. }
  1140. }
  1141. }
  1142. /// <summary>
  1143. /// 控制缩放比的最小值为1%
  1144. /// </summary>
  1145. /// <param name="ratio"></param>
  1146. /// <returns></returns>
  1147. private double GetMinRatio(double ratio)
  1148. {
  1149. if (ratio < 0.01)
  1150. ratio = 0.01;
  1151. return ratio;
  1152. }
  1153. /// <summary>
  1154. /// 控制document窗口与缩放后图片比例,最大值为1
  1155. /// </summary>
  1156. /// <param name="ratio"></param>
  1157. /// <returns></returns>
  1158. private double GetMaxDocumentWithBitmapRatio(double ratio)
  1159. {
  1160. if (ratio > 1)
  1161. ratio = 1;
  1162. return ratio;
  1163. }
  1164. /// <summary>
  1165. /// 刷新当前激活document的缩放比
  1166. /// </summary>
  1167. /// <param name="scaleRatio"></param>
  1168. /// <returns></returns>
  1169. private bool RefreshActiveDocumentScaleFactor(double scaleRatio)
  1170. {
  1171. AppWorkspace.ActiveDocumentWorkspace.ScaleFactor = ScaleFactor.FromDouble(scaleRatio);
  1172. AppWorkspace.ActiveDocumentWorkspace.Refresh();
  1173. return true;
  1174. }
  1175. /// <summary>
  1176. /// 刷新当前激活document的缩放比与滚动条
  1177. /// </summary>
  1178. /// <param name="scaleRatio"></param>
  1179. /// <returns></returns>
  1180. private bool RefreshActiveDocumentScaleFactorAndScroll(double scaleRatio, Point point)
  1181. {
  1182. AppWorkspace.ActiveDocumentWorkspace.ScaleFactor = ScaleFactor.FromDouble(scaleRatio);
  1183. AppWorkspace.ActiveDocumentWorkspace.PanelScrollPosition = point;
  1184. AppWorkspace.ActiveDocumentWorkspace.Refresh();
  1185. return true;
  1186. }
  1187. private void button7_Click(object sender, EventArgs e)
  1188. {
  1189. for (int i = 0; i < this.listView1.Items.Count; i++)
  1190. {
  1191. if (AppWorkspace.DocumentWorkspaces[i].GetFriendlyName().IndexOf('.') > -1)
  1192. {
  1193. this.listView1.Items[i].Text = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName().Substring(0, AppWorkspace.DocumentWorkspaces[i].GetFriendlyName().LastIndexOf('.'));
  1194. this.listView1.Items[i].Name = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName().Substring(0, AppWorkspace.DocumentWorkspaces[i].GetFriendlyName().LastIndexOf('.'));
  1195. }
  1196. else
  1197. {
  1198. this.listView1.Items[i].Text = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  1199. this.listView1.Items[i].Name = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  1200. }
  1201. }
  1202. //string ssss = "333.44.555.666.jpg";
  1203. //int n = ssss.LastIndexOf(".");
  1204. InitData();
  1205. this.listView1.View = View.Details;
  1206. }
  1207. private void button8_Click(object sender, EventArgs e)
  1208. {
  1209. ////初始化图片列表
  1210. //for (int i = 0; i < this.listView1.Items.Count; i++)
  1211. //{
  1212. // this.listView1.Items[i].Text = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  1213. // this.listView1.Items[i].Name = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  1214. //}
  1215. 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);
  1216. InitData();
  1217. this.listView1.View = View.LargeIcon;
  1218. }
  1219. /// <summary>
  1220. /// 折叠展开
  1221. /// </summary>
  1222. /// <param name="sender"></param>
  1223. /// <param name="e"></param>
  1224. private void btn_Hide_Click(object sender, EventArgs e)
  1225. {
  1226. if (btn_Hide.Text == ">>" && this.fromMinSize == this.fromMaxSize)
  1227. {
  1228. this.fromMaxSize = fixedWidth;
  1229. }
  1230. if (this.Width == this.fromMinSize)
  1231. {
  1232. btn_Hide.Text = "<<";
  1233. this.MaximumSize = new Size(0,0);
  1234. this.Width = this.fromMaxSize;
  1235. }
  1236. else
  1237. {
  1238. btn_Hide.Text = ">>";
  1239. this.fromMaxSize = this.Width;
  1240. this.fromMinSize = splitContainer1.SplitterDistance +24;
  1241. this.Width = this.fromMinSize;
  1242. this.MaximumSize = new Size(400, this.Height);
  1243. //this.fromMinSize = this.Width;
  1244. }
  1245. }
  1246. /// <summary>
  1247. /// 配合折叠展开
  1248. /// </summary>
  1249. /// <param name="sender"></param>
  1250. /// <param name="e"></param>
  1251. private void ImageIndexDialog_SizeChanged(object sender, EventArgs e)
  1252. {
  1253. if (this.btn_Hide.Text == ">>")
  1254. {
  1255. splitContainer1.IsSplitterFixed = true;
  1256. splitContainer1.FixedPanel = FixedPanel.Panel1;
  1257. if (this.Width >= this.fromMaxSize)
  1258. {
  1259. panel1.Width = this.Width + extendWidth;
  1260. this.fromMaxSize = this.Width + extendWidth +24;
  1261. }
  1262. //if (this.Width <= this.fromMinSize)
  1263. //{
  1264. // panel1.Width = this.Width + 550;
  1265. // this.fromMaxSize = this.Width + 574;
  1266. //}
  1267. splitContainer1.SplitterDistance = this.Width - 24;
  1268. this.fromMinSize = this.Width;
  1269. return;
  1270. }
  1271. if (this.btn_Hide.Text == "<<")
  1272. {
  1273. splitContainer1.IsSplitterFixed = false;
  1274. splitContainer1.FixedPanel = FixedPanel.None;
  1275. splitContainer1.SplitterDistance = this.fromMinSize - 24;
  1276. this.fromMaxSize = this.Width;
  1277. }
  1278. if (this.Width > this.fromMinSize)
  1279. {
  1280. this.btn_Hide.Text = "<<";
  1281. if (this.MaximumSize.Width == 400)
  1282. this.MaximumSize = new Size(0, 0);
  1283. }
  1284. else
  1285. {
  1286. this.btn_Hide.Text = ">>";
  1287. if (this.MaximumSize.Width != 400)
  1288. this.MaximumSize = new Size(400, this.Height);
  1289. }
  1290. if (this.Width - 24 > panel1.Width || btn_Hide.Text == "<<" || this.Width > this.fromMinSize)
  1291. panel1.Width = this.Width - 24;
  1292. //if (this.btn_Hide.Text == ">>")
  1293. //{
  1294. // splitContainer1.IsSplitterFixed = true;
  1295. // splitContainer1.FixedPanel = FixedPanel.Panel1;
  1296. // //splitContainer1.SplitterDistance = this.Width - 24;
  1297. //}
  1298. //else
  1299. //{
  1300. // splitContainer1.IsSplitterFixed = false;
  1301. // splitContainer1.FixedPanel = FixedPanel.None;
  1302. //}
  1303. }
  1304. private void panel1_SizeChanged(object sender, EventArgs e)
  1305. {
  1306. splitContainer1.SplitterDistance = this.fromMinSize - 24;
  1307. }
  1308. private int index =-1;
  1309. private void splitContainer1_Panel1_SizeChanged(object sender, EventArgs e)
  1310. {
  1311. if (this.fromMinSize != splitContainer1.SplitterDistance + 24)
  1312. {
  1313. this.fromMinSize = splitContainer1.SplitterDistance + 24;
  1314. if (this.listView1.FocusedItem != null)
  1315. {
  1316. index = this.listView1.FocusedItem.Index;
  1317. InitData();
  1318. index = -1;
  1319. }
  1320. }
  1321. if (splitContainer1.SplitterDistance > 376)
  1322. {
  1323. splitContainer1.SplitterDistance = 376;
  1324. }
  1325. }
  1326. private void button10_Click(object sender, EventArgs e)
  1327. {
  1328. using (BatchSaveDialog dialog = new BatchSaveDialog(AppWorkspace))
  1329. {
  1330. if (AppWorkspace.startScriptRecording)
  1331. {
  1332. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  1333. }
  1334. dialog.StartPosition = FormStartPosition.CenterScreen;
  1335. dialog.ShowDialog();
  1336. }
  1337. }
  1338. /// <summary>
  1339. /// 命名规则设置
  1340. /// </summary>
  1341. /// <param name="sender"></param>
  1342. /// <param name="e"></param>
  1343. private void btn_SetUp_Click(object sender, EventArgs e)
  1344. {
  1345. if (AppWorkspace.startScriptRecording)
  1346. {
  1347. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  1348. }
  1349. using (GeneralSettingDialog af = new GeneralSettingDialog(AppWorkspace))
  1350. {
  1351. af.groupBox1.Visible = false;
  1352. af.groupBox2.Location = new Point(6,13);
  1353. af.groupBox5.Location = new Point(6, 136);
  1354. af.groupBox19.Location = new Point(6, 74);
  1355. af.Width = af.Width - af.groupBox1.Width;
  1356. af.StartPosition = FormStartPosition.CenterScreen;
  1357. af.ShowDialog(AppWorkspace);
  1358. }
  1359. }
  1360. public void PreviewRefresh()
  1361. {
  1362. config.Txt1 = comboBox_T1.Text;
  1363. config.Txt2 = comboBox_T2.Text;
  1364. config.Txt3 = comboBox_T2.Text;
  1365. string photoName;
  1366. if (Startup.instance.ruleDB == null)
  1367. {
  1368. photoName = NamingRuleHelper.GetNameFromXml(Startup.instance.configModel, "默认标尺", "0");
  1369. }
  1370. else
  1371. {
  1372. photoName = NamingRuleHelper.GetNameFromXml(Startup.instance.configModel, Startup.instance.ruleDB.ruler_name, Startup.instance.ruleDB.gain_multiple.ToString());
  1373. }
  1374. lblPreview.Text = photoName;
  1375. }
  1376. private void comboBox_T1_TextUpdate(object sender, EventArgs e)
  1377. {
  1378. PreviewRefresh();
  1379. }
  1380. private void comboBox_T2_TextUpdate(object sender, EventArgs e)
  1381. {
  1382. PreviewRefresh();
  1383. }
  1384. private void comboBox_T3_TextUpdate(object sender, EventArgs e)
  1385. {
  1386. PreviewRefresh();
  1387. }
  1388. /// <summary>
  1389. /// 刷新条目名称
  1390. /// </summary>
  1391. public void comboBox_Name_Refresh()
  1392. {
  1393. this.comboBox_Name.SelectedIndexChanged -= new System.EventHandler(this.comboBox_Name_SelectedIndexChanged);
  1394. string[] lstName = config.LstNaming.Select(a => a.name).ToArray();
  1395. this.comboBox_Name.DataSource = lstName;
  1396. this.comboBox_Name.Text = config.CurrentName;
  1397. this.comboBox_Name.SelectedIndexChanged += new System.EventHandler(this.comboBox_Name_SelectedIndexChanged);
  1398. PreviewRefresh();
  1399. }
  1400. /// <summary>
  1401. /// 添加自定义文本1
  1402. /// </summary>
  1403. /// <param name="sender"></param>
  1404. /// <param name="e"></param>
  1405. private void btn_AddT1_Click(object sender, EventArgs e)
  1406. {
  1407. if (comboBox_T1.Text.Trim() == "")
  1408. {
  1409. MessageBox.Show("参数不能为空!");
  1410. return;
  1411. };
  1412. CurrentLocation = 1;
  1413. CustomTxt customTxt = new CustomTxt();
  1414. customTxt.customT = comboBox_T1.Text.Trim();
  1415. if (config.LstCustomTxt == null) config.LstCustomTxt = new CustomTxtModel();
  1416. if (config.LstCustomTxt.customTxts1 == null) config.LstCustomTxt.customTxts1 = new List<CustomTxt>();
  1417. if (Inspect())
  1418. {
  1419. MessageBox.Show("名称重复!");
  1420. return;
  1421. }
  1422. config.LstCustomTxt.customTxts1.Add(customTxt);
  1423. config.Txt1 = comboBox_T1.Text.Trim();
  1424. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
  1425. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  1426. if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  1427. MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
  1428. if (config.LstCustomTxt.customTxts1 != null && config.LstCustomTxt.customTxts1.Count > 0)
  1429. {
  1430. string[] lstName = config.LstCustomTxt.customTxts1.Select(a => a.customT).ToArray();
  1431. this.comboBox_T1.DataSource = lstName;
  1432. if (lstName.Length > 0) this.comboBox_T1.Text = customTxt.customT;
  1433. }
  1434. else this.comboBox_T1.DataSource = null;
  1435. }
  1436. /// <summary>
  1437. /// 添加自定义文本2
  1438. /// </summary>
  1439. /// <param name="sender"></param>
  1440. /// <param name="e"></param>
  1441. private void btn_AddT2_Click(object sender, EventArgs e)
  1442. {
  1443. if (comboBox_T2.Text.Trim() == "")
  1444. {
  1445. MessageBox.Show("参数不能为空!");
  1446. return;
  1447. };
  1448. CurrentLocation = 2;
  1449. CustomTxt customTxt = new CustomTxt();
  1450. customTxt.customT = comboBox_T2.Text.Trim();
  1451. if (config.LstCustomTxt == null) config.LstCustomTxt = new CustomTxtModel();
  1452. if (config.LstCustomTxt.customTxts2 == null) config.LstCustomTxt.customTxts2 = new List<CustomTxt>();
  1453. if (Inspect())
  1454. {
  1455. MessageBox.Show("名称重复!");
  1456. return;
  1457. }
  1458. config.LstCustomTxt.customTxts2.Add(customTxt);
  1459. config.Txt2 = comboBox_T2.Text.Trim();
  1460. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
  1461. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  1462. if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  1463. MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
  1464. if (config.LstCustomTxt.customTxts2 != null && config.LstCustomTxt.customTxts2.Count > 0)
  1465. {
  1466. string[] lstName = config.LstCustomTxt.customTxts2.Select(a => a.customT).ToArray();
  1467. this.comboBox_T2.DataSource = lstName;
  1468. if (lstName.Length > 0) this.comboBox_T2.Text = customTxt.customT;
  1469. }
  1470. else this.comboBox_T2.DataSource = null;
  1471. }
  1472. private void TxtAssignment()
  1473. {
  1474. config.Txt1 = comboBox_T1.Text.Trim();
  1475. config.Txt2 = comboBox_T2.Text.Trim();
  1476. config.Txt3 = comboBox_T3.Text.Trim();
  1477. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
  1478. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  1479. if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  1480. MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
  1481. }
  1482. /// <summary>
  1483. /// 添加自定义文本3
  1484. /// </summary>
  1485. /// <param name="sender"></param>
  1486. /// <param name="e"></param>
  1487. private void btn_AddT3_Click(object sender, EventArgs e)
  1488. {
  1489. if (comboBox_T3.Text.Trim() == "")
  1490. {
  1491. MessageBox.Show("参数不能为空!");
  1492. return;
  1493. };
  1494. CurrentLocation = 3;
  1495. CustomTxt customTxt = new CustomTxt();
  1496. customTxt.customT = comboBox_T3.Text.Trim();
  1497. if (config.LstCustomTxt == null) config.LstCustomTxt = new CustomTxtModel();
  1498. if (config.LstCustomTxt.customTxts3 == null) config.LstCustomTxt.customTxts3 = new List<CustomTxt>();
  1499. if (Inspect())
  1500. {
  1501. MessageBox.Show("名称重复!");
  1502. return;
  1503. }
  1504. config.LstCustomTxt.customTxts3.Add(customTxt);
  1505. config.Txt3 = comboBox_T3.Text.Trim();
  1506. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
  1507. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  1508. if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  1509. MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
  1510. if (config.LstCustomTxt.customTxts3 != null && config.LstCustomTxt.customTxts3.Count > 0)
  1511. {
  1512. string[] lstName = config.LstCustomTxt.customTxts3.Select(a => a.customT).ToArray();
  1513. this.comboBox_T3.DataSource = lstName;
  1514. if (lstName.Length > 0) this.comboBox_T3.Text = customTxt.customT;
  1515. }
  1516. else this.comboBox_T3.DataSource = null;
  1517. }
  1518. //文本检查
  1519. private bool Inspect()
  1520. {
  1521. bool chek = false;
  1522. string name = string.Empty;
  1523. switch (CurrentLocation)
  1524. {
  1525. case 1:
  1526. name = comboBox_T1.Text.Trim();
  1527. if (config.LstCustomTxt.customTxts1.Count > 0)
  1528. {
  1529. string[] lstName = config.LstCustomTxt.customTxts1.Select(a => a.customT).ToArray();
  1530. chek = ((IList)lstName).Contains(name);
  1531. }
  1532. break;
  1533. case 2:
  1534. name = comboBox_T2.Text.Trim();
  1535. if (config.LstCustomTxt.customTxts2.Count > 0)
  1536. {
  1537. string[] lstName = config.LstCustomTxt.customTxts2.Select(a => a.customT).ToArray();
  1538. chek = ((IList)lstName).Contains(name);
  1539. }
  1540. break;
  1541. case 3:
  1542. name = comboBox_T3.Text.Trim();
  1543. if (config.LstCustomTxt.customTxts3.Count > 0)
  1544. {
  1545. string[] lstName = config.LstCustomTxt.customTxts3.Select(a => a.customT).ToArray();
  1546. chek = ((IList)lstName).Contains(name);
  1547. }
  1548. break;
  1549. default:
  1550. break;
  1551. }
  1552. CurrentLocation = -1;
  1553. return chek;
  1554. }
  1555. /// <summary>
  1556. /// 初始化
  1557. /// </summary>
  1558. public void NamingInitialization()
  1559. {
  1560. if (config.LstCustomTxt != null )
  1561. {
  1562. if (config.LstCustomTxt.customTxts1 != null && config.LstCustomTxt.customTxts1.Count > 0)
  1563. {
  1564. string[] lstName = config.LstCustomTxt.customTxts1.Select(a => a.customT).ToArray();
  1565. this.comboBox_T1.DataSource = lstName;
  1566. if (lstName.Length > 0) this.comboBox_T1.Text = config.Txt1;
  1567. }
  1568. else this.comboBox_T1.DataSource = null;
  1569. if (config.LstCustomTxt.customTxts2 != null && config.LstCustomTxt.customTxts2.Count > 0)
  1570. {
  1571. string[] lstName = config.LstCustomTxt.customTxts2.Select(a => a.customT).ToArray();
  1572. this.comboBox_T2.DataSource = lstName;
  1573. if (lstName.Length > 0) this.comboBox_T2.Text = config.Txt2;
  1574. }
  1575. else this.comboBox_T2.DataSource = null;
  1576. if (config.LstCustomTxt.customTxts3 != null && config.LstCustomTxt.customTxts3.Count > 0)
  1577. {
  1578. string[] lstName = config.LstCustomTxt.customTxts3.Select(a => a.customT).ToArray();
  1579. this.comboBox_T3.DataSource = lstName;
  1580. if (lstName.Length > 0) this.comboBox_T3.Text = config.Txt3;
  1581. }
  1582. else this.comboBox_T3.DataSource = null;
  1583. }
  1584. this.comboBox_T1.SelectedIndexChanged += new System.EventHandler(this.comboBox_T1_SelectedIndexChanged);
  1585. this.comboBox_T2.SelectedIndexChanged += new System.EventHandler(this.comboBox_T2_SelectedIndexChanged);
  1586. this.comboBox_T3.SelectedIndexChanged += new System.EventHandler(this.comboBox_T3_SelectedIndexChanged);
  1587. }
  1588. private void btn_DelT1_Click(object sender, EventArgs e)
  1589. {
  1590. if (comboBox_T1.Text.Trim() == "")
  1591. {
  1592. MessageBox.Show("参数不能为空!");
  1593. return;
  1594. };
  1595. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretcteddata.text") + "?", PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  1596. if (dr == DialogResult.Cancel) return;
  1597. CurrentLocation = 1;
  1598. if (config.LstCustomTxt == null || config.LstCustomTxt.customTxts1 == null || !Inspect())
  1599. {
  1600. MessageBox.Show("不存在此文本!");
  1601. return;
  1602. }
  1603. for (int i = 0; i < config.LstCustomTxt.customTxts1.Count; i++)
  1604. {
  1605. if (comboBox_T1.Text.Trim().Equals(config.LstCustomTxt.customTxts1[i].customT))
  1606. config.LstCustomTxt.customTxts1.Remove(config.LstCustomTxt.customTxts1[i]);
  1607. }
  1608. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
  1609. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  1610. if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  1611. MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
  1612. if (config.LstCustomTxt.customTxts1 != null && config.LstCustomTxt.customTxts1.Count > 0)
  1613. {
  1614. string[] lstName = config.LstCustomTxt.customTxts1.Select(a => a.customT).ToArray();
  1615. this.comboBox_T1.DataSource = lstName;
  1616. }
  1617. else this.comboBox_T1.DataSource = null;
  1618. }
  1619. private void btn_DelT2_Click(object sender, EventArgs e)
  1620. {
  1621. if (comboBox_T2.Text.Trim() == "")
  1622. {
  1623. MessageBox.Show("参数不能为空!");
  1624. return;
  1625. };
  1626. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretcteddata.text") + "?", PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  1627. if (dr == DialogResult.Cancel) return;
  1628. CurrentLocation = 2;
  1629. if (config.LstCustomTxt == null || config.LstCustomTxt.customTxts2 == null || !Inspect())
  1630. {
  1631. MessageBox.Show("不存在此文本!");
  1632. return;
  1633. }
  1634. for (int i = 0; i < config.LstCustomTxt.customTxts2.Count; i++)
  1635. {
  1636. if (comboBox_T2.Text.Trim().Equals(config.LstCustomTxt.customTxts2[i].customT))
  1637. config.LstCustomTxt.customTxts2.Remove(config.LstCustomTxt.customTxts2[i]);
  1638. }
  1639. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
  1640. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  1641. if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  1642. MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
  1643. if (config.LstCustomTxt.customTxts2 != null && config.LstCustomTxt.customTxts2.Count > 0)
  1644. {
  1645. string[] lstName = config.LstCustomTxt.customTxts2.Select(a => a.customT).ToArray();
  1646. this.comboBox_T2.DataSource = lstName;
  1647. }
  1648. else this.comboBox_T2.DataSource = null;
  1649. }
  1650. private void btn_DelT3_Click(object sender, EventArgs e)
  1651. {
  1652. if (comboBox_T3.Text.Trim() == "")
  1653. {
  1654. MessageBox.Show("参数不能为空!");
  1655. return;
  1656. };
  1657. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretcteddata.text") + "?", PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  1658. if (dr == DialogResult.Cancel) return;
  1659. CurrentLocation = 3;
  1660. if (config.LstCustomTxt == null || config.LstCustomTxt.customTxts3 == null || !Inspect())
  1661. {
  1662. MessageBox.Show("不存在此文本!");
  1663. return;
  1664. }
  1665. for (int i = 0; i < config.LstCustomTxt.customTxts3.Count; i++)
  1666. {
  1667. if (comboBox_T3.Text.Trim().Equals(config.LstCustomTxt.customTxts3[i].customT))
  1668. config.LstCustomTxt.customTxts3.Remove(config.LstCustomTxt.customTxts3[i]);
  1669. }
  1670. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
  1671. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  1672. if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  1673. MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
  1674. if (config.LstCustomTxt.customTxts3 != null && config.LstCustomTxt.customTxts3.Count > 0)
  1675. {
  1676. string[] lstName = config.LstCustomTxt.customTxts3.Select(a => a.customT).ToArray();
  1677. this.comboBox_T3.DataSource = lstName;
  1678. }
  1679. else this.comboBox_T3.DataSource = null;
  1680. }
  1681. /// <summary>
  1682. /// 鼠标事件-右键
  1683. /// </summary>
  1684. /// <param name="sender"></param>
  1685. /// <param name="e"></param>
  1686. private void listView1_MouseClick(object sender, MouseEventArgs e)
  1687. {
  1688. ListView listView = (ListView)sender;
  1689. ListViewItem item = listView.GetItemAt(e.X, e.Y);
  1690. if (item != null && e.Button == MouseButtons.Right)
  1691. {
  1692. this.contextMenuStrip1.Show(listView, e.X, e.Y);
  1693. }
  1694. }
  1695. /// <summary>
  1696. /// 右键保存
  1697. /// </summary>
  1698. /// <param name="sender"></param>
  1699. /// <param name="e"></param>
  1700. private void toolStripMenuItem1_Click(object sender, EventArgs e)
  1701. {
  1702. if (AppWorkspace.ActiveDocumentWorkspace != null)
  1703. {
  1704. if (AppWorkspace.startScriptRecording)
  1705. {
  1706. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  1707. }
  1708. AppWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
  1709. AppWorkspace.ActiveDocumentWorkspace.DoSaveNew();
  1710. }
  1711. InitData();
  1712. }
  1713. /// <summary>
  1714. /// 右键另存
  1715. /// </summary>
  1716. /// <param name="sender"></param>
  1717. /// <param name="e"></param>
  1718. private void toolStripMenuItem2_Click(object sender, EventArgs e)
  1719. {
  1720. if (AppWorkspace.ActiveDocumentWorkspace != null)
  1721. {
  1722. if (AppWorkspace.startScriptRecording)
  1723. {
  1724. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  1725. }
  1726. AppWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
  1727. AppWorkspace.ActiveDocumentWorkspace.DoSaveAsNew();
  1728. }
  1729. InitData();
  1730. }
  1731. /// <summary>
  1732. /// 右键强制关闭
  1733. /// </summary>
  1734. /// <param name="sender"></param>
  1735. /// <param name="e"></param>
  1736. private void toolStripMenuItem3_Click(object sender, EventArgs e)
  1737. {
  1738. if (this.AppWorkspace.DocumentWorkspaces.Length > 0 && this.AppWorkspace.ActiveDocumentWorkspace != null)
  1739. {
  1740. if (AppWorkspace.startScriptRecording)
  1741. {
  1742. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  1743. }
  1744. this.AppWorkspace.ActiveDocumentWorkspace.Document.Dirty = false;
  1745. this.AppWorkspace.PerformAction(new CloseWorkspaceAction());
  1746. }
  1747. InitData();
  1748. }
  1749. private Bitmap copyedBitmap;//复制的图片
  1750. private int nameNum = 0;//命名使用
  1751. /// <summary>
  1752. /// 右键复制图片
  1753. /// </summary>
  1754. /// <param name="sender"></param>
  1755. /// <param name="e"></param>
  1756. private void toolStripMenuItem4_Click(object sender, EventArgs e)
  1757. {
  1758. if (AppWorkspace.ActiveDocumentWorkspace != null && AppWorkspace.ActiveDocumentWorkspace.CompositionSurface != null)
  1759. {
  1760. if (AppWorkspace.startScriptRecording)
  1761. {
  1762. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  1763. }
  1764. Bitmap temp = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap();
  1765. copyedBitmap = new Bitmap(temp.Width, temp.Height);
  1766. Graphics graphics = Graphics.FromImage(copyedBitmap);
  1767. graphics.DrawImage(temp, 0, 0, temp.Width, temp.Height);
  1768. if (AppWorkspace.ActiveDocumentWorkspace.GraphicsList.IsExsitSpecificObject(DrawToolType.ImageCut))
  1769. {
  1770. //获取裁剪的矩形区域
  1771. List<DrawObject> objList = AppWorkspace.ActiveDocumentWorkspace.GraphicsList.GetDrawToolTypeList(DrawToolType.ImageCut);
  1772. ImageCutDraw imageCutDraw = (ImageCutDraw)objList[0];
  1773. RectangleF cutRectangle = imageCutDraw.Rectangle;
  1774. copyedBitmap = DrawRulerHelper.KiCut(copyedBitmap, (int)cutRectangle.X, (int)cutRectangle.Y, (int)cutRectangle.Width, (int)cutRectangle.Height);
  1775. }
  1776. }
  1777. if (copyedBitmap != null)
  1778. {
  1779. if (AppWorkspace.startScriptRecording)
  1780. {
  1781. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  1782. }
  1783. DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
  1784. Document document = Document.FromImage(copyedBitmap);
  1785. dw.Document = document;
  1786. //图片命名
  1787. nameNum++;
  1788. int numLength = nameNum.ToString().Length;
  1789. string joinName = "";
  1790. switch (numLength)
  1791. {
  1792. case 1:
  1793. joinName = "00" + nameNum;
  1794. break;
  1795. case 2:
  1796. joinName = "0" + nameNum;
  1797. break;
  1798. default:
  1799. joinName = nameNum.ToString();
  1800. break;
  1801. }
  1802. dw.xmlSaveModel = AppWorkspace.ActiveDocumentWorkspace.xmlSaveModel;
  1803. dw.rules = AppWorkspace.ActiveDocumentWorkspace.rules;
  1804. dw.fileText = PdnResources.GetString("Menu.Copythepicture.Text") + "-" + joinName;
  1805. AppWorkspace.ActiveDocumentWorkspace = dw;
  1806. }
  1807. InitData();
  1808. }
  1809. private void SplitContainerSize()
  1810. {
  1811. splitContainer1.Size = new Size(800, 450);
  1812. }
  1813. private void comboBox_T1_SelectedIndexChanged(object sender, EventArgs e)
  1814. {
  1815. TxtAssignment();
  1816. PreviewRefresh();
  1817. }
  1818. private void comboBox_T2_SelectedIndexChanged(object sender, EventArgs e)
  1819. {
  1820. TxtAssignment();
  1821. PreviewRefresh();
  1822. }
  1823. private void comboBox_T3_SelectedIndexChanged(object sender, EventArgs e)
  1824. {
  1825. TxtAssignment();
  1826. PreviewRefresh();
  1827. }
  1828. private void comboBox_Name_SelectedIndexChanged(object sender, EventArgs e)
  1829. {
  1830. if (comboBox_Name.Text.Trim() == "")
  1831. {
  1832. MessageBox.Show("参数不能为空!");
  1833. return;
  1834. }
  1835. config.CurrentName = comboBox_Name.Text.Trim();
  1836. comboBox_Name_SelectedIndex();
  1837. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(config);
  1838. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  1839. if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  1840. MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text"));
  1841. PreviewRefresh();
  1842. }
  1843. private void comboBox_Name_SelectedIndex()
  1844. {
  1845. string CurrentName = config.CurrentName;
  1846. if (config.LstNaming.Count > 0)
  1847. {
  1848. foreach (NamingMethod item in config.LstNaming)
  1849. {
  1850. if (CurrentName.Equals(item.name))
  1851. {
  1852. config.NamePrefix = item.NamePrefix;
  1853. config.NameFormat = item.NameFormat;
  1854. config.NumberNum = item.NumberNum;
  1855. config.NameStatus = item.NameStatus;
  1856. config.ContinueNum = item.ContinueNum;
  1857. }
  1858. }
  1859. }
  1860. }
  1861. CreateNameDialog dialog;
  1862. public string imgType = string.Empty;
  1863. private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
  1864. {
  1865. string imgName = this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].GetFriendlyName();
  1866. int index = 0;
  1867. if (imgName.Contains('.'))
  1868. {
  1869. index = imgName.LastIndexOf('.');
  1870. imgType = imgName.Substring(index);
  1871. //从下一个索引开始截取
  1872. imgName = imgName.Substring(0, index);
  1873. }
  1874. else
  1875. {
  1876. imgType = "";
  1877. }
  1878. dialog = new CreateNameDialog(this);
  1879. dialog.Text = "重命名";
  1880. dialog.StartPosition = FormStartPosition.CenterParent;
  1881. dialog.SetTextBoxValue(imgName);
  1882. dialog.textBox1.MaxLength = 999;
  1883. dialog.ShowDialog();
  1884. }
  1885. /// <summary>
  1886. /// 新建文件夹的结果函数
  1887. /// </summary>
  1888. /// <param name="name"></param>
  1889. public override void GetCreateName(string name)
  1890. {
  1891. DocumentWorkspace iDocumentWorkspace = AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index];
  1892. string imgName = iDocumentWorkspace.GetFriendlyName();
  1893. int index = 0;
  1894. if (imgName.Contains('.'))
  1895. {
  1896. index = imgName.LastIndexOf('.');
  1897. imgName = imgName.Substring(0, index);
  1898. }
  1899. //获取图片路径
  1900. string fileName;
  1901. FileType fileType;
  1902. SaveConfigToken saveConfigToken;
  1903. iDocumentWorkspace.GetDocumentSaveOptions(out fileName, out fileType, out saveConfigToken);
  1904. string path = Path.GetDirectoryName(fileName);
  1905. string filePath = path + "\\" + name + imgType;
  1906. string xmlName = path + "\\" + imgName + ".xml";
  1907. string xmlPath = path + "\\" + name + ".xml";
  1908. if (System.IO.File.Exists(fileName)) System.IO.File.Move(fileName, filePath);//更改图片名称
  1909. if (System.IO.File.Exists(xmlName)) System.IO.File.Move(xmlName, xmlPath);//更改xml文件名称
  1910. this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].fileText = name + imgType;
  1911. this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].UpdateDw2buttonName(name + imgType);
  1912. this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].picName = name + imgType;
  1913. this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].Refresh();
  1914. this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].filePath = filePath;
  1915. this.listView1.Items[this.listView1.FocusedItem.Index].Text = name + imgType;
  1916. this.listView1.Items[this.listView1.FocusedItem.Index].Name = name + imgType;
  1917. //InitData();
  1918. dialog.Close();
  1919. }
  1920. private void ImageIndexDialog_FormClosing(object sender, FormClosingEventArgs e)
  1921. {
  1922. this.AppWorkspace.toolBar.RefreshBtnSelect(false, "ImageIndex");
  1923. this.AppWorkspace.toolsPanel.RefreshBtnSelect(false, "ImageIndex");
  1924. config.Txt1 = comboBox_T1.Text;
  1925. config.Txt2 = comboBox_T2.Text;
  1926. config.Txt3 = comboBox_T2.Text;
  1927. }
  1928. }
  1929. }