RuleAddForm.cs 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797
  1. using OpenCvSharp;
  2. using PaintDotNet.Adjust.BaseImage;
  3. using PaintDotNet.Base.CommTool;
  4. using PaintDotNet.Base.SettingModel;
  5. using PaintDotNet.CustomControl;
  6. using PaintDotNet.DbOpreate.DbBll;
  7. using PaintDotNet.DbOpreate.DbModel;
  8. using PaintDotNet.ImageCollect;
  9. using System;
  10. using System.Drawing;
  11. using System.Drawing.Drawing2D;
  12. using System.IO;
  13. using System.Windows.Forms;
  14. namespace PaintDotNet.Measuring
  15. {
  16. /// <summary>
  17. /// 标尺编辑/删除界面
  18. /// </summary>
  19. internal class RuleAddForm : PdnBaseForm
  20. {
  21. /// <summary>
  22. /// 公共按钮
  23. /// </summary>
  24. private CommonControlButtons commonControlButtons;
  25. /// <summary>
  26. /// 在各种弹窗中使用
  27. /// </summary>
  28. private DocumentWorkspaceWindow documentWorkspace;
  29. /// <summary>
  30. /// 步骤
  31. /// </summary>
  32. private byte step = 1;
  33. /// <summary>
  34. /// 方向
  35. /// </summary>
  36. private byte direction = 0;
  37. /// <summary>
  38. /// 标尺图片
  39. /// </summary>
  40. private Bitmap bitmap;
  41. /// <summary>
  42. /// 起止点
  43. /// </summary>
  44. private System.Drawing.Point startPoint, endPoint;
  45. /// <summary>
  46. /// x、y轴数值
  47. /// </summary>
  48. private int x, y;
  49. /// <summary>
  50. /// 绘制标尺的线宽
  51. /// </summary>
  52. private int width;
  53. /// <summary>
  54. /// 字体
  55. /// </summary>
  56. private Font font;
  57. /// <summary>
  58. /// 笔刷
  59. /// </summary>
  60. private Brush brush = new SolidBrush(Color.Red);
  61. /// <summary>
  62. /// 标尺xml文件,编辑标尺时使用
  63. /// </summary>
  64. public RulerFileModel ruleFileModel;
  65. /// <summary>
  66. /// 标尺数据,编辑标尺时使用
  67. /// </summary>
  68. public mic_rulers ruleModel;
  69. /// <summary>
  70. /// 1新增 2编辑
  71. /// </summary>
  72. public int status;
  73. /// <summary>
  74. /// 调色板
  75. /// </summary>
  76. PaintDotNet.ColorsForm colorsForm1;
  77. // Create the outline for our custom end cap.
  78. GraphicsPath hPath = new GraphicsPath();
  79. // Construct the hook-shaped end cap.
  80. CustomLineCap HookCap;
  81. public AppWorkspace appWorkspace;
  82. #region 像素跟踪
  83. private Mat mat, ImageROI, bmat = new Mat();
  84. /// <summary>
  85. /// rgb像素点
  86. /// </summary>
  87. private Vec3b bgr;
  88. /// <summary>
  89. /// hls像素点
  90. /// </summary>
  91. private double h, s, v;
  92. /// <summary>
  93. /// 缩放倍数
  94. /// </summary>
  95. private int scale;
  96. /// <summary>
  97. /// 中间十字和圆的颜色
  98. /// 根据左侧的panel的被选中的背景色变化
  99. /// </summary>
  100. private Color color = Color.Red;
  101. /// <summary>
  102. /// 按下标记
  103. /// </summary>
  104. private bool pressFlag;
  105. #endregion
  106. #region 控件
  107. private System.Windows.Forms.GroupBox groupBox1;
  108. private System.Windows.Forms.Button button1;
  109. private System.Windows.Forms.Button button3;
  110. private System.Windows.Forms.Button button2;
  111. private System.Windows.Forms.GroupBox groupBox2;
  112. private System.Windows.Forms.Button button4;
  113. private System.Windows.Forms.Button button5;
  114. private System.Windows.Forms.Button button6;
  115. private System.Windows.Forms.Button button9;
  116. private System.Windows.Forms.Button button8;
  117. private System.Windows.Forms.Button button7;
  118. private System.Windows.Forms.Panel panel1;
  119. private System.Windows.Forms.Label label7;
  120. private System.Windows.Forms.Label label1;
  121. private System.Windows.Forms.NumericUpDown numericUpDown1;
  122. private System.Windows.Forms.ColorDialog colorDialog1;
  123. private System.Windows.Forms.GroupBox groupBox3;
  124. private System.Windows.Forms.GroupBox groupBox4;
  125. private System.Windows.Forms.TextBox textBox1;
  126. private System.Windows.Forms.TextBox textBox6;
  127. private System.Windows.Forms.TextBox textBox5;
  128. private System.Windows.Forms.TextBox textBox4;
  129. private System.Windows.Forms.TextBox textBox2;
  130. private System.Windows.Forms.GroupBox groupBox5;
  131. private System.Windows.Forms.TextBox textBox12;
  132. private System.Windows.Forms.TextBox textBox11;
  133. private System.Windows.Forms.TextBox textBox10;
  134. private System.Windows.Forms.TextBox textBox9;
  135. private System.Windows.Forms.TextBox textBox8;
  136. private System.Windows.Forms.TextBox textBox7;
  137. private System.Windows.Forms.Panel panel2;
  138. private CustomControl.LinearColorPickerControl linearColorPickerControl1;
  139. private PictureBox pictureBox1;
  140. private Label label6;
  141. private Label label5;
  142. private Label label4;
  143. private Label label3;
  144. private Label label2;
  145. private Label label8;
  146. private Label label9;
  147. private TrackBar trackBar1;
  148. private NumericUpDown numericUpDown2;
  149. private Label label10;
  150. private Label label11;
  151. private Label label17;
  152. private Label label16;
  153. private Label label15;
  154. private Label label14;
  155. private Label label13;
  156. private Label label12;
  157. private Label label23;
  158. private Label label22;
  159. private Label label21;
  160. private Label label20;
  161. private Label label19;
  162. private Label label18;
  163. private NumericUpDown numericUpDown3;
  164. private Label label24;
  165. private System.Windows.Forms.ComboBox comboBox1;
  166. #endregion
  167. #region Windows Form Designer generated code
  168. private void InitializeLanguageText()
  169. {
  170. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  171. this.button6.Text = PdnResources.GetString("Menu.Previous.text");
  172. this.button5.Text = PdnResources.GetString("Menu.Nextstep.text");
  173. this.button3.Text = PdnResources.GetString("Menu.thirdstep.text");
  174. this.button2.Text = PdnResources.GetString("Menu.Secondstep.text");
  175. this.button1.Text = PdnResources.GetString("Menu.firststep.text");
  176. this.groupBox2.Text = PdnResources.GetString("Menu.Selectimagefrom.text");
  177. this.label1.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
  178. this.label7.Text = PdnResources.GetString("Menu.color.text") + ":";
  179. this.button9.Text = PdnResources.GetString("Menu.Anydirection.text");
  180. this.button8.Text = PdnResources.GetString("Menu.Verticaldirection.text");
  181. this.button7.Text = PdnResources.GetString("Menu.horizontaldirection.text");
  182. this.button4.Text = PdnResources.GetString("Menu.Openimage.text");
  183. this.groupBox3.Text = PdnResources.GetString("Menu.Rulerimage.text");
  184. this.groupBox4.Text = PdnResources.GetString("Menu.params.text");
  185. this.label17.Text = PdnResources.GetString("Menu.Pixellength.text") + ":";
  186. this.label16.Text = PdnResources.GetString("Menu.Physicallength.text") + ":";
  187. this.label15.Text = PdnResources.GetString("Menu.Resolution.text") + ":";
  188. this.label14.Text = PdnResources.GetString("Menu.unit.text") + ":";
  189. this.label13.Text = PdnResources.GetString("Menu.LabelAction.DrawGainNumber.Text") + ":";
  190. this.label12.Text = PdnResources.GetString("Menu.name.text") + ":";
  191. this.groupBox5.Text = PdnResources.GetString("Menu.Expand.text");
  192. this.label23.Text = PdnResources.GetString("Menu.microscope.text") + ":";
  193. this.label22.Text = PdnResources.GetString("Menu.Objectlens.text") + ":";
  194. this.label21.Text = PdnResources.GetString("Menu.thecamera.text") + ":";
  195. this.label20.Text = PdnResources.GetString("Menu.oculars.text") + ":";
  196. this.label19.Text = PdnResources.GetString("Menu.interface.text") + ":";
  197. this.label18.Text = PdnResources.GetString("Menu.magnificationchanger.text") + ":";
  198. this.label9.Text = PdnResources.GetString("Menu.Times.text");
  199. this.label24.Text = PdnResources.GetString("Menu.Fontsize.text");
  200. }
  201. /// <summary>
  202. /// Required method for Designer support - do not modify
  203. /// the contents of this method with the code editor.
  204. /// </summary>
  205. private void InitializeComponent()
  206. {
  207. this.groupBox1 = new System.Windows.Forms.GroupBox();
  208. this.button6 = new System.Windows.Forms.Button();
  209. this.button5 = new System.Windows.Forms.Button();
  210. this.button3 = new System.Windows.Forms.Button();
  211. this.button2 = new System.Windows.Forms.Button();
  212. this.button1 = new System.Windows.Forms.Button();
  213. this.groupBox2 = new System.Windows.Forms.GroupBox();
  214. this.numericUpDown3 = new System.Windows.Forms.NumericUpDown();
  215. this.label24 = new System.Windows.Forms.Label();
  216. this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
  217. this.label1 = new System.Windows.Forms.Label();
  218. this.panel1 = new System.Windows.Forms.Panel();
  219. this.label7 = new System.Windows.Forms.Label();
  220. this.button9 = new System.Windows.Forms.Button();
  221. this.button8 = new System.Windows.Forms.Button();
  222. this.button7 = new System.Windows.Forms.Button();
  223. this.button4 = new System.Windows.Forms.Button();
  224. this.colorDialog1 = new System.Windows.Forms.ColorDialog();
  225. this.groupBox3 = new System.Windows.Forms.GroupBox();
  226. this.groupBox4 = new System.Windows.Forms.GroupBox();
  227. this.label17 = new System.Windows.Forms.Label();
  228. this.label16 = new System.Windows.Forms.Label();
  229. this.label15 = new System.Windows.Forms.Label();
  230. this.label14 = new System.Windows.Forms.Label();
  231. this.label13 = new System.Windows.Forms.Label();
  232. this.label12 = new System.Windows.Forms.Label();
  233. this.comboBox1 = new System.Windows.Forms.ComboBox();
  234. this.textBox6 = new System.Windows.Forms.TextBox();
  235. this.textBox5 = new System.Windows.Forms.TextBox();
  236. this.textBox4 = new System.Windows.Forms.TextBox();
  237. this.textBox2 = new System.Windows.Forms.TextBox();
  238. this.textBox1 = new System.Windows.Forms.TextBox();
  239. this.groupBox5 = new System.Windows.Forms.GroupBox();
  240. this.label23 = new System.Windows.Forms.Label();
  241. this.label22 = new System.Windows.Forms.Label();
  242. this.label21 = new System.Windows.Forms.Label();
  243. this.label20 = new System.Windows.Forms.Label();
  244. this.label19 = new System.Windows.Forms.Label();
  245. this.label18 = new System.Windows.Forms.Label();
  246. this.textBox12 = new System.Windows.Forms.TextBox();
  247. this.textBox11 = new System.Windows.Forms.TextBox();
  248. this.textBox10 = new System.Windows.Forms.TextBox();
  249. this.textBox9 = new System.Windows.Forms.TextBox();
  250. this.textBox8 = new System.Windows.Forms.TextBox();
  251. this.textBox7 = new System.Windows.Forms.TextBox();
  252. this.panel2 = new System.Windows.Forms.Panel();
  253. this.label10 = new System.Windows.Forms.Label();
  254. this.label11 = new System.Windows.Forms.Label();
  255. this.label9 = new System.Windows.Forms.Label();
  256. this.trackBar1 = new System.Windows.Forms.TrackBar();
  257. this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
  258. this.label6 = new System.Windows.Forms.Label();
  259. this.label5 = new System.Windows.Forms.Label();
  260. this.label4 = new System.Windows.Forms.Label();
  261. this.label3 = new System.Windows.Forms.Label();
  262. this.label2 = new System.Windows.Forms.Label();
  263. this.label8 = new System.Windows.Forms.Label();
  264. this.pictureBox1 = new System.Windows.Forms.PictureBox();
  265. this.linearColorPickerControl1 = new PaintDotNet.CustomControl.LinearColorPickerControl();
  266. this.groupBox1.SuspendLayout();
  267. this.groupBox2.SuspendLayout();
  268. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).BeginInit();
  269. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
  270. this.groupBox4.SuspendLayout();
  271. this.groupBox5.SuspendLayout();
  272. this.panel2.SuspendLayout();
  273. ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
  274. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
  275. ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
  276. this.SuspendLayout();
  277. //
  278. // groupBox1
  279. //
  280. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  281. | System.Windows.Forms.AnchorStyles.Left)));
  282. this.groupBox1.Controls.Add(this.button6);
  283. this.groupBox1.Controls.Add(this.button5);
  284. this.groupBox1.Controls.Add(this.button3);
  285. this.groupBox1.Controls.Add(this.button2);
  286. this.groupBox1.Controls.Add(this.button1);
  287. this.groupBox1.Location = new System.Drawing.Point(13, 13);
  288. this.groupBox1.Name = "groupBox1";
  289. this.groupBox1.Size = new System.Drawing.Size(115, 445);
  290. this.groupBox1.TabIndex = 1;
  291. this.groupBox1.TabStop = false;
  292. //
  293. // button6
  294. //
  295. this.button6.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
  296. | System.Windows.Forms.AnchorStyles.Right)));
  297. this.button6.Location = new System.Drawing.Point(20, 383);
  298. this.button6.Name = "button6";
  299. this.button6.Size = new System.Drawing.Size(75, 23);
  300. this.button6.TabIndex = 4;
  301. this.button6.Text = "上一步";
  302. this.button6.UseVisualStyleBackColor = true;
  303. this.button6.Click += new System.EventHandler(this.button6_Click);
  304. //
  305. // button5
  306. //
  307. this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
  308. | System.Windows.Forms.AnchorStyles.Right)));
  309. this.button5.Location = new System.Drawing.Point(20, 412);
  310. this.button5.Name = "button5";
  311. this.button5.Size = new System.Drawing.Size(75, 23);
  312. this.button5.TabIndex = 3;
  313. this.button5.Text = "下一步";
  314. this.button5.UseVisualStyleBackColor = true;
  315. this.button5.Click += new System.EventHandler(this.button5_Click);
  316. //
  317. // button3
  318. //
  319. this.button3.Location = new System.Drawing.Point(20, 89);
  320. this.button3.Name = "button3";
  321. this.button3.Size = new System.Drawing.Size(75, 23);
  322. this.button3.TabIndex = 2;
  323. this.button3.Text = "第三步";
  324. this.button3.UseVisualStyleBackColor = true;
  325. this.button3.Click += new System.EventHandler(this.button3_Click);
  326. //
  327. // button2
  328. //
  329. this.button2.Location = new System.Drawing.Point(20, 59);
  330. this.button2.Name = "button2";
  331. this.button2.Size = new System.Drawing.Size(75, 23);
  332. this.button2.TabIndex = 1;
  333. this.button2.Text = "第二步";
  334. this.button2.UseVisualStyleBackColor = true;
  335. this.button2.Click += new System.EventHandler(this.button2_Click);
  336. //
  337. // button1
  338. //
  339. this.button1.Location = new System.Drawing.Point(20, 29);
  340. this.button1.Name = "button1";
  341. this.button1.Size = new System.Drawing.Size(75, 23);
  342. this.button1.TabIndex = 0;
  343. this.button1.Text = "第一步";
  344. this.button1.UseVisualStyleBackColor = true;
  345. this.button1.Click += new System.EventHandler(this.button1_Click);
  346. //
  347. // groupBox2
  348. //
  349. this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  350. | System.Windows.Forms.AnchorStyles.Right)));
  351. this.groupBox2.Controls.Add(this.label24);
  352. this.groupBox2.Controls.Add(this.numericUpDown1);
  353. this.groupBox2.Controls.Add(this.numericUpDown3);
  354. this.groupBox2.Controls.Add(this.label1);
  355. this.groupBox2.Controls.Add(this.panel1);
  356. this.groupBox2.Controls.Add(this.label7);
  357. this.groupBox2.Controls.Add(this.button9);
  358. this.groupBox2.Controls.Add(this.button8);
  359. this.groupBox2.Controls.Add(this.button7);
  360. this.groupBox2.Controls.Add(this.button4);
  361. this.groupBox2.Location = new System.Drawing.Point(134, 13);
  362. this.groupBox2.Name = "groupBox2";
  363. this.groupBox2.Size = new System.Drawing.Size(779, 52);
  364. this.groupBox2.TabIndex = 2;
  365. this.groupBox2.TabStop = false;
  366. this.groupBox2.Text = "从...选择图像";
  367. //
  368. // numericUpDown3
  369. //
  370. this.numericUpDown3.Location = new System.Drawing.Point(323, 22);
  371. this.numericUpDown3.Minimum = new decimal(new int[] {
  372. 1,
  373. 0,
  374. 0,
  375. 0});
  376. this.numericUpDown3.Name = "numericUpDown3";
  377. this.numericUpDown3.Size = new System.Drawing.Size(72, 21);
  378. this.numericUpDown3.TabIndex = 17;
  379. this.numericUpDown3.Value = new decimal(new int[] {
  380. 12,
  381. 0,
  382. 0,
  383. 0});
  384. this.numericUpDown3.ValueChanged += new System.EventHandler(this.numericUpDown3_ValueChanged);
  385. //
  386. // label24
  387. //
  388. this.label24.AutoSize = true;
  389. this.label24.Location = new System.Drawing.Point(278, 26);
  390. this.label24.Name = "label24";
  391. this.label24.Size = new System.Drawing.Size(41, 12);
  392. this.label24.TabIndex = 16;
  393. this.label24.Text = "字号:";
  394. //
  395. // numericUpDown1
  396. //
  397. this.numericUpDown1.Location = new System.Drawing.Point(181, 22);
  398. this.numericUpDown1.Maximum = new decimal(new int[] {
  399. 99999,
  400. 0,
  401. 0,
  402. 0});
  403. this.numericUpDown1.Minimum = new decimal(new int[] {
  404. 1,
  405. 0,
  406. 0,
  407. 0});
  408. this.numericUpDown1.Name = "numericUpDown1";
  409. this.numericUpDown1.Size = new System.Drawing.Size(72, 21);
  410. this.numericUpDown1.TabIndex = 15;
  411. this.numericUpDown1.Value = new decimal(new int[] {
  412. 3,
  413. 0,
  414. 0,
  415. 0});
  416. this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged);
  417. //
  418. // label1
  419. //
  420. this.label1.AutoSize = true;
  421. this.label1.Location = new System.Drawing.Point(136, 26);
  422. this.label1.Name = "label1";
  423. this.label1.Size = new System.Drawing.Size(41, 12);
  424. this.label1.TabIndex = 4;
  425. this.label1.Text = "线宽:";
  426. //
  427. // panel1
  428. //
  429. this.panel1.BackColor = System.Drawing.Color.Red;
  430. this.panel1.Location = new System.Drawing.Point(55, 22);
  431. this.panel1.Name = "panel1";
  432. this.panel1.Size = new System.Drawing.Size(72, 21);
  433. this.panel1.TabIndex = 14;
  434. this.panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown);
  435. //
  436. // label7
  437. //
  438. this.label7.AutoSize = true;
  439. this.label7.Location = new System.Drawing.Point(13, 26);
  440. this.label7.Name = "label7";
  441. this.label7.Size = new System.Drawing.Size(41, 12);
  442. this.label7.TabIndex = 13;
  443. this.label7.Text = "颜色:";
  444. //
  445. // button9
  446. //
  447. this.button9.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  448. this.button9.Location = new System.Drawing.Point(617, 21);
  449. this.button9.Name = "button9";
  450. this.button9.Size = new System.Drawing.Size(75, 23);
  451. this.button9.TabIndex = 3;
  452. this.button9.Text = "任意方向";
  453. this.button9.UseVisualStyleBackColor = true;
  454. this.button9.Click += new System.EventHandler(this.button9_Click);
  455. //
  456. // button8
  457. //
  458. this.button8.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  459. this.button8.Location = new System.Drawing.Point(535, 21);
  460. this.button8.Name = "button8";
  461. this.button8.Size = new System.Drawing.Size(75, 23);
  462. this.button8.TabIndex = 2;
  463. this.button8.Text = "垂直方向";
  464. this.button8.UseVisualStyleBackColor = true;
  465. this.button8.Click += new System.EventHandler(this.button8_Click);
  466. //
  467. // button7
  468. //
  469. this.button7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  470. this.button7.Location = new System.Drawing.Point(453, 21);
  471. this.button7.Name = "button7";
  472. this.button7.Size = new System.Drawing.Size(75, 23);
  473. this.button7.TabIndex = 1;
  474. this.button7.Text = "水平方向";
  475. this.button7.UseVisualStyleBackColor = true;
  476. this.button7.Click += new System.EventHandler(this.button7_Click);
  477. //
  478. // button4
  479. //
  480. this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  481. | System.Windows.Forms.AnchorStyles.Right)));
  482. this.button4.Location = new System.Drawing.Point(698, 21);
  483. this.button4.Name = "button4";
  484. this.button4.Size = new System.Drawing.Size(75, 23);
  485. this.button4.TabIndex = 0;
  486. this.button4.Text = "保存标尺";
  487. this.button4.UseVisualStyleBackColor = true;
  488. this.button4.Click += new System.EventHandler(this.button4_Click);
  489. //
  490. // groupBox3
  491. //
  492. this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  493. | System.Windows.Forms.AnchorStyles.Left)
  494. | System.Windows.Forms.AnchorStyles.Right)));
  495. this.groupBox3.Location = new System.Drawing.Point(135, 72);
  496. this.groupBox3.Name = "groupBox3";
  497. this.groupBox3.Size = new System.Drawing.Size(585, 386);
  498. this.groupBox3.TabIndex = 3;
  499. this.groupBox3.TabStop = false;
  500. this.groupBox3.Text = "标尺图像";
  501. //
  502. // groupBox4
  503. //
  504. this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  505. this.groupBox4.Controls.Add(this.label17);
  506. this.groupBox4.Controls.Add(this.label16);
  507. this.groupBox4.Controls.Add(this.label15);
  508. this.groupBox4.Controls.Add(this.label14);
  509. this.groupBox4.Controls.Add(this.label13);
  510. this.groupBox4.Controls.Add(this.label12);
  511. this.groupBox4.Controls.Add(this.comboBox1);
  512. this.groupBox4.Controls.Add(this.textBox6);
  513. this.groupBox4.Controls.Add(this.textBox5);
  514. this.groupBox4.Controls.Add(this.textBox4);
  515. this.groupBox4.Controls.Add(this.textBox2);
  516. this.groupBox4.Controls.Add(this.textBox1);
  517. this.groupBox4.Location = new System.Drawing.Point(726, 72);
  518. this.groupBox4.Name = "groupBox4";
  519. this.groupBox4.Size = new System.Drawing.Size(187, 189);
  520. this.groupBox4.TabIndex = 4;
  521. this.groupBox4.TabStop = false;
  522. this.groupBox4.Visible = false;
  523. //
  524. // label17
  525. //
  526. this.label17.AutoSize = true;
  527. this.label17.Location = new System.Drawing.Point(9, 164);
  528. this.label17.Name = "label17";
  529. this.label17.Size = new System.Drawing.Size(0, 12);
  530. this.label17.TabIndex = 13;
  531. //
  532. // label16
  533. //
  534. this.label16.AutoSize = true;
  535. this.label16.Location = new System.Drawing.Point(9, 136);
  536. this.label16.Name = "label16";
  537. this.label16.Size = new System.Drawing.Size(0, 12);
  538. this.label16.TabIndex = 12;
  539. //
  540. // label15
  541. //
  542. this.label15.AutoSize = true;
  543. this.label15.Location = new System.Drawing.Point(9, 108);
  544. this.label15.Name = "label15";
  545. this.label15.Size = new System.Drawing.Size(0, 12);
  546. this.label15.TabIndex = 11;
  547. //
  548. // label14
  549. //
  550. this.label14.AutoSize = true;
  551. this.label14.Location = new System.Drawing.Point(9, 80);
  552. this.label14.Name = "label14";
  553. this.label14.Size = new System.Drawing.Size(0, 12);
  554. this.label14.TabIndex = 10;
  555. //
  556. // label13
  557. //
  558. this.label13.AutoSize = true;
  559. this.label13.Location = new System.Drawing.Point(9, 52);
  560. this.label13.Name = "label13";
  561. this.label13.Size = new System.Drawing.Size(0, 12);
  562. this.label13.TabIndex = 9;
  563. //
  564. // label12
  565. //
  566. this.label12.AutoSize = true;
  567. this.label12.Location = new System.Drawing.Point(9, 24);
  568. this.label12.Name = "label12";
  569. this.label12.Size = new System.Drawing.Size(0, 12);
  570. this.label12.TabIndex = 8;
  571. //
  572. // comboBox1
  573. //
  574. this.comboBox1.FormattingEnabled = true;
  575. this.comboBox1.Location = new System.Drawing.Point(75, 76);
  576. this.comboBox1.Name = "comboBox1";
  577. this.comboBox1.Size = new System.Drawing.Size(106, 20);
  578. this.comboBox1.TabIndex = 7;
  579. //
  580. // textBox6
  581. //
  582. this.textBox6.Location = new System.Drawing.Point(75, 160);
  583. this.textBox6.Name = "textBox6";
  584. this.textBox6.Size = new System.Drawing.Size(106, 21);
  585. this.textBox6.TabIndex = 6;
  586. //
  587. // textBox5
  588. //
  589. this.textBox5.Location = new System.Drawing.Point(75, 132);
  590. this.textBox5.Name = "textBox5";
  591. this.textBox5.Size = new System.Drawing.Size(106, 21);
  592. this.textBox5.TabIndex = 5;
  593. //
  594. // textBox4
  595. //
  596. this.textBox4.Location = new System.Drawing.Point(75, 104);
  597. this.textBox4.Name = "textBox4";
  598. this.textBox4.Size = new System.Drawing.Size(106, 21);
  599. this.textBox4.TabIndex = 4;
  600. //
  601. // textBox2
  602. //
  603. this.textBox2.Location = new System.Drawing.Point(76, 48);
  604. this.textBox2.Name = "textBox2";
  605. this.textBox2.Size = new System.Drawing.Size(106, 21);
  606. this.textBox2.TabIndex = 2;
  607. //
  608. // textBox1
  609. //
  610. this.textBox1.Location = new System.Drawing.Point(75, 20);
  611. this.textBox1.Name = "textBox1";
  612. this.textBox1.Size = new System.Drawing.Size(106, 21);
  613. this.textBox1.TabIndex = 1;
  614. //
  615. // groupBox5
  616. //
  617. this.groupBox5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  618. this.groupBox5.Controls.Add(this.label23);
  619. this.groupBox5.Controls.Add(this.label22);
  620. this.groupBox5.Controls.Add(this.label21);
  621. this.groupBox5.Controls.Add(this.label20);
  622. this.groupBox5.Controls.Add(this.label19);
  623. this.groupBox5.Controls.Add(this.label18);
  624. this.groupBox5.Controls.Add(this.textBox12);
  625. this.groupBox5.Controls.Add(this.textBox11);
  626. this.groupBox5.Controls.Add(this.textBox10);
  627. this.groupBox5.Controls.Add(this.textBox9);
  628. this.groupBox5.Controls.Add(this.textBox8);
  629. this.groupBox5.Controls.Add(this.textBox7);
  630. this.groupBox5.Location = new System.Drawing.Point(726, 267);
  631. this.groupBox5.Name = "groupBox5";
  632. this.groupBox5.Size = new System.Drawing.Size(187, 191);
  633. this.groupBox5.TabIndex = 5;
  634. this.groupBox5.TabStop = false;
  635. this.groupBox5.Visible = false;
  636. //
  637. // label23
  638. //
  639. this.label23.AutoSize = true;
  640. this.label23.Location = new System.Drawing.Point(9, 165);
  641. this.label23.Name = "label23";
  642. this.label23.Size = new System.Drawing.Size(0, 12);
  643. this.label23.TabIndex = 11;
  644. //
  645. // label22
  646. //
  647. this.label22.AutoSize = true;
  648. this.label22.Location = new System.Drawing.Point(9, 137);
  649. this.label22.Name = "label22";
  650. this.label22.Size = new System.Drawing.Size(0, 12);
  651. this.label22.TabIndex = 10;
  652. //
  653. // label21
  654. //
  655. this.label21.AutoSize = true;
  656. this.label21.Location = new System.Drawing.Point(9, 109);
  657. this.label21.Name = "label21";
  658. this.label21.Size = new System.Drawing.Size(0, 12);
  659. this.label21.TabIndex = 9;
  660. //
  661. // label20
  662. //
  663. this.label20.AutoSize = true;
  664. this.label20.Location = new System.Drawing.Point(9, 81);
  665. this.label20.Name = "label20";
  666. this.label20.Size = new System.Drawing.Size(0, 12);
  667. this.label20.TabIndex = 8;
  668. //
  669. // label19
  670. //
  671. this.label19.AutoSize = true;
  672. this.label19.Location = new System.Drawing.Point(9, 53);
  673. this.label19.Name = "label19";
  674. this.label19.Size = new System.Drawing.Size(0, 12);
  675. this.label19.TabIndex = 7;
  676. //
  677. // label18
  678. //
  679. this.label18.AutoSize = true;
  680. this.label18.Location = new System.Drawing.Point(9, 25);
  681. this.label18.Name = "label18";
  682. this.label18.Size = new System.Drawing.Size(0, 12);
  683. this.label18.TabIndex = 6;
  684. //
  685. // textBox12
  686. //
  687. this.textBox12.Location = new System.Drawing.Point(75, 161);
  688. this.textBox12.Name = "textBox12";
  689. this.textBox12.Size = new System.Drawing.Size(106, 21);
  690. this.textBox12.TabIndex = 5;
  691. //
  692. // textBox11
  693. //
  694. this.textBox11.Location = new System.Drawing.Point(75, 133);
  695. this.textBox11.Name = "textBox11";
  696. this.textBox11.Size = new System.Drawing.Size(106, 21);
  697. this.textBox11.TabIndex = 4;
  698. //
  699. // textBox10
  700. //
  701. this.textBox10.Location = new System.Drawing.Point(75, 105);
  702. this.textBox10.Name = "textBox10";
  703. this.textBox10.Size = new System.Drawing.Size(106, 21);
  704. this.textBox10.TabIndex = 3;
  705. //
  706. // textBox9
  707. //
  708. this.textBox9.Location = new System.Drawing.Point(75, 77);
  709. this.textBox9.Name = "textBox9";
  710. this.textBox9.Size = new System.Drawing.Size(106, 21);
  711. this.textBox9.TabIndex = 2;
  712. //
  713. // textBox8
  714. //
  715. this.textBox8.Location = new System.Drawing.Point(75, 49);
  716. this.textBox8.Name = "textBox8";
  717. this.textBox8.Size = new System.Drawing.Size(106, 21);
  718. this.textBox8.TabIndex = 1;
  719. //
  720. // textBox7
  721. //
  722. this.textBox7.Location = new System.Drawing.Point(75, 21);
  723. this.textBox7.Name = "textBox7";
  724. this.textBox7.Size = new System.Drawing.Size(106, 21);
  725. this.textBox7.TabIndex = 0;
  726. //
  727. // panel2
  728. //
  729. this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  730. | System.Windows.Forms.AnchorStyles.Right)));
  731. this.panel2.BackColor = System.Drawing.SystemColors.Control;
  732. this.panel2.Controls.Add(this.label10);
  733. this.panel2.Controls.Add(this.label11);
  734. this.panel2.Controls.Add(this.label9);
  735. this.panel2.Controls.Add(this.trackBar1);
  736. this.panel2.Controls.Add(this.numericUpDown2);
  737. this.panel2.Controls.Add(this.label6);
  738. this.panel2.Controls.Add(this.label5);
  739. this.panel2.Controls.Add(this.label4);
  740. this.panel2.Controls.Add(this.label3);
  741. this.panel2.Controls.Add(this.label2);
  742. this.panel2.Controls.Add(this.label8);
  743. this.panel2.Controls.Add(this.pictureBox1);
  744. this.panel2.Controls.Add(this.linearColorPickerControl1);
  745. this.panel2.Location = new System.Drawing.Point(726, 79);
  746. this.panel2.Name = "panel2";
  747. this.panel2.Size = new System.Drawing.Size(187, 379);
  748. this.panel2.TabIndex = 0;
  749. this.panel2.Visible = false;
  750. //
  751. // label10
  752. //
  753. this.label10.AutoSize = true;
  754. this.label10.BackColor = System.Drawing.Color.Transparent;
  755. this.label10.Location = new System.Drawing.Point(6, 22);
  756. this.label10.Name = "label10";
  757. this.label10.Size = new System.Drawing.Size(17, 12);
  758. this.label10.TabIndex = 30;
  759. this.label10.Text = "Y=";
  760. //
  761. // label11
  762. //
  763. this.label11.AutoSize = true;
  764. this.label11.BackColor = System.Drawing.Color.Transparent;
  765. this.label11.Location = new System.Drawing.Point(6, 6);
  766. this.label11.Name = "label11";
  767. this.label11.Size = new System.Drawing.Size(17, 12);
  768. this.label11.TabIndex = 29;
  769. this.label11.Text = "X=";
  770. //
  771. // label9
  772. //
  773. this.label9.AutoSize = true;
  774. this.label9.Location = new System.Drawing.Point(47, 113);
  775. this.label9.Name = "label9";
  776. this.label9.Size = new System.Drawing.Size(0, 12);
  777. this.label9.TabIndex = 28;
  778. //
  779. // trackBar1
  780. //
  781. this.trackBar1.Location = new System.Drawing.Point(70, 109);
  782. this.trackBar1.Minimum = 1;
  783. this.trackBar1.Name = "trackBar1";
  784. this.trackBar1.Size = new System.Drawing.Size(91, 45);
  785. this.trackBar1.TabIndex = 27;
  786. this.trackBar1.TickStyle = System.Windows.Forms.TickStyle.None;
  787. this.trackBar1.Value = 1;
  788. this.trackBar1.ValueChanged += new System.EventHandler(this.trackBar1_ValueChanged);
  789. //
  790. // numericUpDown2
  791. //
  792. this.numericUpDown2.Location = new System.Drawing.Point(6, 109);
  793. this.numericUpDown2.Maximum = new decimal(new int[] {
  794. 10,
  795. 0,
  796. 0,
  797. 0});
  798. this.numericUpDown2.Minimum = new decimal(new int[] {
  799. 1,
  800. 0,
  801. 0,
  802. 0});
  803. this.numericUpDown2.Name = "numericUpDown2";
  804. this.numericUpDown2.Size = new System.Drawing.Size(37, 21);
  805. this.numericUpDown2.TabIndex = 26;
  806. this.numericUpDown2.Value = new decimal(new int[] {
  807. 1,
  808. 0,
  809. 0,
  810. 0});
  811. this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged);
  812. //
  813. // label6
  814. //
  815. this.label6.AutoSize = true;
  816. this.label6.Location = new System.Drawing.Point(126, 90);
  817. this.label6.Name = "label6";
  818. this.label6.Size = new System.Drawing.Size(11, 12);
  819. this.label6.TabIndex = 25;
  820. this.label6.Text = "V";
  821. //
  822. // label5
  823. //
  824. this.label5.AutoSize = true;
  825. this.label5.Location = new System.Drawing.Point(126, 74);
  826. this.label5.Name = "label5";
  827. this.label5.Size = new System.Drawing.Size(11, 12);
  828. this.label5.TabIndex = 24;
  829. this.label5.Text = "S";
  830. //
  831. // label4
  832. //
  833. this.label4.AutoSize = true;
  834. this.label4.Location = new System.Drawing.Point(126, 58);
  835. this.label4.Name = "label4";
  836. this.label4.Size = new System.Drawing.Size(11, 12);
  837. this.label4.TabIndex = 23;
  838. this.label4.Text = "H";
  839. //
  840. // label3
  841. //
  842. this.label3.AutoSize = true;
  843. this.label3.Location = new System.Drawing.Point(126, 36);
  844. this.label3.Name = "label3";
  845. this.label3.Size = new System.Drawing.Size(11, 12);
  846. this.label3.TabIndex = 22;
  847. this.label3.Text = "B";
  848. //
  849. // label2
  850. //
  851. this.label2.AutoSize = true;
  852. this.label2.Location = new System.Drawing.Point(126, 20);
  853. this.label2.Name = "label2";
  854. this.label2.Size = new System.Drawing.Size(11, 12);
  855. this.label2.TabIndex = 21;
  856. this.label2.Text = "G";
  857. //
  858. // label8
  859. //
  860. this.label8.AutoSize = true;
  861. this.label8.Location = new System.Drawing.Point(126, 4);
  862. this.label8.Name = "label8";
  863. this.label8.Size = new System.Drawing.Size(35, 12);
  864. this.label8.TabIndex = 20;
  865. this.label8.Text = "R=255";
  866. //
  867. // pictureBox1
  868. //
  869. this.pictureBox1.Location = new System.Drawing.Point(3, 3);
  870. this.pictureBox1.Name = "pictureBox1";
  871. this.pictureBox1.Size = new System.Drawing.Size(100, 100);
  872. this.pictureBox1.TabIndex = 19;
  873. this.pictureBox1.TabStop = false;
  874. this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
  875. //
  876. // linearColorPickerControl1
  877. //
  878. this.linearColorPickerControl1.Count = 1;
  879. this.linearColorPickerControl1.CustomGradient = new System.Drawing.Color[] {
  880. System.Drawing.Color.White,
  881. System.Drawing.Color.Yellow,
  882. System.Drawing.Color.Red,
  883. System.Drawing.Color.Green,
  884. System.Drawing.Color.Blue,
  885. System.Drawing.Color.Black};
  886. this.linearColorPickerControl1.DrawFarNub = true;
  887. this.linearColorPickerControl1.DrawNearNub = true;
  888. this.linearColorPickerControl1.Location = new System.Drawing.Point(106, 3);
  889. this.linearColorPickerControl1.MaxColor = System.Drawing.Color.White;
  890. this.linearColorPickerControl1.MinColor = System.Drawing.Color.Black;
  891. this.linearColorPickerControl1.Name = "linearColorPickerControl1";
  892. this.linearColorPickerControl1.Orientation = System.Windows.Forms.Orientation.Vertical;
  893. this.linearColorPickerControl1.Size = new System.Drawing.Size(14, 100);
  894. this.linearColorPickerControl1.TabIndex = 18;
  895. this.linearColorPickerControl1.TabStop = false;
  896. this.linearColorPickerControl1.Value = 153;
  897. this.linearColorPickerControl1.ValueChanged += new PaintDotNet.IndexEventHandler(this.linearColorPickerControl1_ValueChanged);
  898. //
  899. // RuleAddForm
  900. //
  901. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  902. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  903. this.ClientSize = new System.Drawing.Size(922, 467);
  904. this.Controls.Add(this.panel2);
  905. this.Controls.Add(this.groupBox5);
  906. this.Controls.Add(this.groupBox4);
  907. this.Controls.Add(this.groupBox3);
  908. this.Controls.Add(this.groupBox2);
  909. this.Controls.Add(this.groupBox1);
  910. this.Name = "RuleAddForm";
  911. this.Text = "新建标尺";
  912. this.Controls.SetChildIndex(this.groupBox1, 0);
  913. this.Controls.SetChildIndex(this.groupBox2, 0);
  914. this.Controls.SetChildIndex(this.groupBox3, 0);
  915. this.Controls.SetChildIndex(this.groupBox4, 0);
  916. this.Controls.SetChildIndex(this.groupBox5, 0);
  917. this.Controls.SetChildIndex(this.panel2, 0);
  918. this.groupBox1.ResumeLayout(false);
  919. this.groupBox2.ResumeLayout(false);
  920. this.groupBox2.PerformLayout();
  921. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).EndInit();
  922. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
  923. this.groupBox4.ResumeLayout(false);
  924. this.groupBox4.PerformLayout();
  925. this.groupBox5.ResumeLayout(false);
  926. this.groupBox5.PerformLayout();
  927. this.panel2.ResumeLayout(false);
  928. this.panel2.PerformLayout();
  929. ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
  930. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
  931. ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
  932. this.ResumeLayout(false);
  933. }
  934. #endregion
  935. //<summary>
  936. //初始化其他控件
  937. //</summary>
  938. private void InitOtherTools()
  939. {
  940. //
  941. //调色板
  942. //
  943. this.colorsForm1 = new ColorsForm();
  944. this.colorsForm1.StartPosition = FormStartPosition.CenterScreen;
  945. this.colorsForm1.setSaveBtn_Click(new System.EventHandler(this.colorsForm1Changed));
  946. //
  947. //字号
  948. //
  949. font = new Font("常规", (int)this.numericUpDown3.Value);
  950. }
  951. private void colorsForm1Changed(object sender, EventArgs e)
  952. {
  953. this.panel1.BackColor = this.colorsForm1.UserPrimaryColor.ToColor();
  954. this.colorsForm1.Close();
  955. }
  956. /// <summary>
  957. /// 像素跟踪的颜色控件
  958. /// </summary>
  959. /// <param name="sender"></param>
  960. /// <param name="ce"></param>
  961. private void linearColorPickerControl1_ValueChanged(object sender, IndexEventArgs ce)
  962. {
  963. this.color = this.linearColorPickerControl1.ValueToColor(this.linearColorPickerControl1.Value);
  964. this.pictureBox1.Refresh();
  965. }
  966. /// <summary>
  967. /// 构造函数
  968. /// </summary>
  969. /// <param name="status">1新增 2编辑</param>
  970. public RuleAddForm(int status, AppWorkspace appWorkspace)
  971. {
  972. this.status = status;
  973. this.appWorkspace = appWorkspace;
  974. InitializeComponent();
  975. InitializeLanguageText();
  976. InitOtherTools();
  977. this.Text = PdnResources.GetString("Menu.Imagement.Rulersetting.Newruler.text");
  978. //
  979. //初始化图像控件
  980. //
  981. this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
  982. this.documentWorkspace.Dock = DockStyle.Fill;
  983. this.documentWorkspace.HookMouseEvents();
  984. this.documentWorkspace.pixelTrackingEnabled = false;
  985. //this.documentWorkspace.SurfaceBox.RemoveMouseEvent();
  986. this.documentWorkspace.AuxiliaryLineEnabled = true;
  987. this.documentWorkspace.Visible = false;
  988. this.groupBox3.Controls.Add(documentWorkspace);
  989. //
  990. //初始化操作按钮
  991. //
  992. this.commonControlButtons = new CommonControlButtons();
  993. this.commonControlButtons.Dock = DockStyle.Top;
  994. this.commonControlButtons.Height = 30;
  995. this.groupBox3.Controls.Add(commonControlButtons);
  996. this.groupBox3.Width = this.groupBox3.Width + this.groupBox4.Width + 6;
  997. InitializeUI();
  998. this.comboBox1.Text = PdnResources.GetString("Menu.easeselectmeasurementunit.Text");
  999. this.comboBox1.DataSource = new BindingSource(InvariantData.ruleUnitsDictionary, null);
  1000. this.comboBox1.DisplayMember = "Value";
  1001. this.comboBox1.ValueMember = "Key";
  1002. this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
  1003. this.comboBox1.SelectedIndex = 4;
  1004. InitializeHint();
  1005. this.width = (int)this.numericUpDown1.Value;
  1006. this.textBox4.ReadOnly = true;
  1007. InitCommonButtonEvent();
  1008. //自定义线形的线帽,已达到标尺垂线的效果
  1009. hPath.AddLine(new PointF(-6, 0), new PointF(6, 0));
  1010. HookCap = new CustomLineCap(null, hPath);
  1011. HookCap.SetStrokeCaps(LineCap.Flat, LineCap.Flat);
  1012. HookCap.WidthScale = 0.5f;
  1013. }
  1014. private void InitCommonButtonEvent()
  1015. {
  1016. this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
  1017. this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
  1018. this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
  1019. this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
  1020. this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
  1021. this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
  1022. }
  1023. private void zoomInButton_Click(object sender, EventArgs e)
  1024. {
  1025. this.documentWorkspace.ZoomIn();
  1026. }
  1027. private void zoomOutButton_Click(object sender, EventArgs e)
  1028. {
  1029. this.documentWorkspace.ZoomOut();
  1030. }
  1031. private void zoomToWindowButton_Click(object sender, EventArgs e)
  1032. {
  1033. this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  1034. }
  1035. private void actualSizeButton_Click(object sender, EventArgs e)
  1036. {
  1037. this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  1038. this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
  1039. }
  1040. private void pointerButton_Click(object sender, EventArgs e)
  1041. {
  1042. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer;
  1043. }
  1044. private void mobileModeButton_Click(object sender, EventArgs e)
  1045. {
  1046. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
  1047. }
  1048. /// <summary>
  1049. /// 编辑时初始化数据
  1050. /// </summary>
  1051. public void InitializeEditData()
  1052. {
  1053. //打开图片
  1054. if(ruleFileModel!=null && ruleFileModel.picBase64!=null)
  1055. {
  1056. //string base64Img = "data:image/png;base64," + ruleFileModel.picBase64;
  1057. bitmap = DrawRulerHelper.Base64StringToImage(ruleFileModel.picBase64);
  1058. Document document = Document.FromImage(bitmap);
  1059. documentWorkspace.Document = document;
  1060. this.documentWorkspace.Visible = true;
  1061. startPoint = new System.Drawing.Point(ruleFileModel.startPointX, ruleFileModel.startPointY);
  1062. endPoint = new System.Drawing.Point(ruleFileModel.endPointX, ruleFileModel.endPointY);
  1063. this.panel1.BackColor = Color.FromArgb(ruleFileModel.lineColor);
  1064. this.brush = new SolidBrush(this.panel1.BackColor);
  1065. this.numericUpDown1.Value = ruleFileModel.lineWidth;
  1066. this.numericUpDown3.Value = Math.Max(1, ruleFileModel.textSize);
  1067. AddPictureBoxEvent();
  1068. }
  1069. if(ruleModel != null)
  1070. {
  1071. this.textBox2.Text = ruleModel.gain_multiple.ToString();
  1072. this.textBox12.Text = ruleModel.microscope;
  1073. this.textBox11.Text = ruleModel.objective_lens;
  1074. this.textBox5.Text = ruleModel.physical_length.ToString();
  1075. this.textBox6.Text = ruleModel.pixel_length.ToString();
  1076. this.textBox10.Text = ruleModel.ruler_camera;
  1077. this.textBox8.Text = ruleModel.ruler_connector;
  1078. this.textBox9.Text = ruleModel.ruler_eyepiece;
  1079. this.textBox1.Text = ruleModel.ruler_name;
  1080. this.comboBox1.SelectedValue = ruleModel.ruler_units;
  1081. this.textBox7.Text = ruleModel.ruler_zoom;
  1082. this.textBox4.Text = ruleModel.ruler_width + "×" + ruleModel.ruler_height;
  1083. }
  1084. }
  1085. private void MouseDownHandler(object sender, MouseEventArgs e)
  1086. {
  1087. if (documentWorkspace != null)
  1088. {
  1089. //if (documentWorkspace.Tool != null)
  1090. // documentWorkspace.Tool.PerformMouseDown(e);
  1091. }
  1092. }
  1093. private void MouseMoveHandler(object sender, MouseEventArgs e)
  1094. {
  1095. if (documentWorkspace != null)
  1096. {
  1097. //if (documentWorkspace.Tool != null)
  1098. // documentWorkspace.Tool.PerformMouseMove(e);
  1099. }
  1100. }
  1101. private void MouseUpHandler(object sender, MouseEventArgs e)
  1102. {
  1103. if (documentWorkspace != null)
  1104. {
  1105. //if (documentWorkspace.Tool != null)
  1106. // documentWorkspace.Tool.PerformMouseUp(e);
  1107. }
  1108. }
  1109. /// <summary>
  1110. /// 打开图片/保存标尺
  1111. /// 公用按钮
  1112. /// </summary>
  1113. /// <param name="sender"></param>
  1114. /// <param name="e"></param>
  1115. private void button4_Click(object sender, EventArgs e)
  1116. {
  1117. //保存标尺
  1118. if (step == 3)
  1119. {
  1120. if (this.textBox1.Text.Equals(""))
  1121. {
  1122. MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterarulername.text"));
  1123. return;
  1124. }
  1125. if (this.textBox2.Text.Equals(""))
  1126. {
  1127. MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterthemagnification.text"));
  1128. return;
  1129. }
  1130. if (this.textBox5.Text.Equals(""))
  1131. {
  1132. MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterthephysicallength.text"));
  1133. return;
  1134. }
  1135. if (startPoint == endPoint)
  1136. {
  1137. MessageBox.Show(PdnResources.GetString("Menu.asereturntothesecondsteptodrawther.Text")+"!");
  1138. return;
  1139. }
  1140. if (this.status == 1)
  1141. {
  1142. try
  1143. {
  1144. //判断标尺是否存在
  1145. for (int i = 0; i < Startup.instance.mic_rulersAll.Count; i++)
  1146. {
  1147. if (Startup.instance.mic_rulersAll[i].ruler_name.Equals(this.textBox1.Text))
  1148. {
  1149. MessageBox.Show(PdnResources.GetString("Menu.hecurrentscalenamealreadyexists.Text"));
  1150. return;
  1151. }
  1152. }
  1153. //组织数据,保存到数据库
  1154. mic_rulers rule = new mic_rulers();
  1155. rule.gain_multiple = decimal.Parse(this.textBox2.Text);
  1156. if (rule.gain_multiple<1)
  1157. {
  1158. MessageBox.Show("放大倍数错误,请检查!");
  1159. return;
  1160. }
  1161. rule.microscope = this.textBox12.Text;
  1162. rule.objective_lens = this.textBox11.Text;
  1163. rule.physical_length = decimal.Parse(this.textBox5.Text);
  1164. rule.pixel_length = float.Parse(this.textBox6.Text);
  1165. rule.ruler_camera = this.textBox10.Text;
  1166. rule.ruler_connector = this.textBox8.Text;
  1167. rule.ruler_eyepiece = this.textBox9.Text;
  1168. rule.ruler_height = this.bitmap.Height;
  1169. rule.ruler_name = this.textBox1.Text;
  1170. rule.ruler_units = (int)this.comboBox1.SelectedValue;
  1171. rule.ruler_width = this.bitmap.Width;
  1172. rule.ruler_zoom = this.textBox7.Text;
  1173. rule.ruler_type = 1;
  1174. mic_rulers_BLL.Add(rule);
  1175. Startup.instance.mic_rulersAll.Add(rule);
  1176. //生成xml文件
  1177. ruleFileModel = new RulerFileModel();
  1178. ruleFileModel.startPointX = startPoint.X;
  1179. ruleFileModel.startPointY = startPoint.Y;
  1180. ruleFileModel.endPointX = endPoint.X;
  1181. ruleFileModel.endPointY = endPoint.Y;
  1182. ruleFileModel.lineColor = this.panel1.BackColor.ToArgb();
  1183. ruleFileModel.lineWidth = width;
  1184. ruleFileModel.textSize = this.numericUpDown3.Value;
  1185. ruleFileModel.picBase64 = DrawRulerHelper.ImgToBase64String(this.documentWorkspace.CompositionSurface.CreateAliasedBitmap());
  1186. //保存xml文件
  1187. string userInfoXml = XmlSerializeHelper.XmlSerialize<RulerFileModel>(ruleFileModel);
  1188. string folderPath = Application.StartupPath + "\\RuleFile\\";
  1189. if (!Directory.Exists(folderPath)) Directory.CreateDirectory(folderPath);
  1190. string filePath = rule.id + ".xml";
  1191. FileOperationHelper.WriteStringToFile(userInfoXml, folderPath + filePath, FileMode.Create);
  1192. this.Close();
  1193. }
  1194. catch (Exception)
  1195. {
  1196. System.Console.WriteLine(e.ToString());
  1197. MessageBox.Show(PdnResources.GetString("Menu.Rulerinformationsavingfaile.Text"));
  1198. }
  1199. }
  1200. else if(this.status == 2)
  1201. {
  1202. try
  1203. {
  1204. //判断标尺是否存在
  1205. for (int i = 0; i < Startup.instance.mic_rulersAll.Count; i++)
  1206. {
  1207. if (Startup.instance.mic_rulersAll[i].id == ruleModel.id)
  1208. continue;
  1209. if (Startup.instance.mic_rulersAll[i].ruler_name.Equals(this.textBox1.Text))
  1210. {
  1211. MessageBox.Show(PdnResources.GetString("Menu.hecurrentscalenamealreadyexists.Text"));
  1212. return;
  1213. }
  1214. }
  1215. //组织数据,保存到数据库
  1216. ruleModel.gain_multiple = decimal.Parse(this.textBox2.Text);
  1217. if (ruleModel.gain_multiple < 1)
  1218. {
  1219. MessageBox.Show("放大倍数错误,请检查!");
  1220. return;
  1221. }
  1222. ruleModel.microscope = this.textBox12.Text;
  1223. ruleModel.objective_lens = this.textBox11.Text;
  1224. ruleModel.physical_length = decimal.Parse(this.textBox5.Text);
  1225. ruleModel.pixel_length = float.Parse(this.textBox6.Text);
  1226. ruleModel.ruler_camera = this.textBox10.Text;
  1227. ruleModel.ruler_connector = this.textBox8.Text;
  1228. ruleModel.ruler_eyepiece = this.textBox9.Text;
  1229. ruleModel.ruler_height = this.bitmap.Height;
  1230. ruleModel.ruler_name = this.textBox1.Text;
  1231. ruleModel.ruler_units = (int)this.comboBox1.SelectedValue;
  1232. ruleModel.ruler_width = this.bitmap.Width;
  1233. ruleModel.ruler_zoom = this.textBox7.Text;
  1234. ruleModel.ruler_type = 1;
  1235. mic_rulers_BLL.Update(ruleModel);
  1236. //生成xml文件
  1237. ruleFileModel = new RulerFileModel();
  1238. ruleFileModel.startPointX = startPoint.X;
  1239. ruleFileModel.startPointY = startPoint.Y;
  1240. ruleFileModel.endPointX = endPoint.X;
  1241. ruleFileModel.endPointY = endPoint.Y;
  1242. ruleFileModel.lineColor = this.panel1.BackColor.ToArgb();
  1243. ruleFileModel.lineWidth = width;
  1244. ruleFileModel.textSize = this.numericUpDown3.Value;
  1245. ruleFileModel.picBase64 = DrawRulerHelper.ImgToBase64String(this.documentWorkspace.CompositionSurface.CreateAliasedBitmap());
  1246. //保存xml文件
  1247. string userInfoXml = XmlSerializeHelper.XmlSerialize<RulerFileModel>(ruleFileModel);
  1248. string filePath = Application.StartupPath + "\\RuleFile\\" + ruleModel.id + ".xml";
  1249. FileOperationHelper.WriteStringToFile(userInfoXml, filePath, FileMode.Create);
  1250. this.Close();
  1251. this.appWorkspace.RefreshActiveRuler();
  1252. }
  1253. catch (Exception)
  1254. {
  1255. System.Console.WriteLine(e.ToString());
  1256. MessageBox.Show(PdnResources.GetString("Menu.Rulerinformationsavingfaile.Text"));
  1257. }
  1258. }
  1259. //刷新标尺列表
  1260. this.appWorkspace.RefueshRuleList();
  1261. //刷新预览窗口
  1262. if (CameraPreviewDialog.cameraPreviewDialog != null)
  1263. CameraPreviewDialog.cameraPreviewDialog.BindingRule();
  1264. }
  1265. else
  1266. {
  1267. OpenFileDialog dialog = new OpenFileDialog();
  1268. dialog.Filter = "图像文件(*.gif;*.jpg;*.jpeg;*.png;*.tif;*.bmp)|*.gif;*.jpg;*.jpeg;*.png;*.tif;*.bmp";
  1269. dialog.ShowDialog();
  1270. if (dialog.FileName != String.Empty)
  1271. {
  1272. try
  1273. {
  1274. bitmap = new Bitmap(dialog.FileName);
  1275. Document document = Document.FromImage(bitmap);
  1276. documentWorkspace.Document = document;
  1277. this.documentWorkspace.Visible = true;
  1278. this.textBox4.Text = bitmap.Width + "×" + bitmap.Height;
  1279. this.mat = null;
  1280. this.startPoint = System.Drawing.Point.Empty;
  1281. this.endPoint = System.Drawing.Point.Empty;
  1282. RemoveDocEvent();
  1283. AddPictureBoxEvent();
  1284. }
  1285. catch(Exception)
  1286. {
  1287. MessageBox.Show("打开图像失败, 请确认");
  1288. }
  1289. }
  1290. }
  1291. }
  1292. /// <summary>
  1293. /// 下一步
  1294. /// </summary>
  1295. /// <param name="sender"></param>
  1296. /// <param name="e"></param>
  1297. private void button5_Click(object sender, EventArgs e)
  1298. {
  1299. if (step == 1) {
  1300. if (bitmap == null)
  1301. {
  1302. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectrulerimage.Text")+"!");
  1303. return;
  1304. }
  1305. }
  1306. if (!this.panel2.Visible && !this.groupBox4.Visible)
  1307. {
  1308. this.groupBox3.Width = this.groupBox3.Width - this.groupBox4.Width - 3;
  1309. }
  1310. step++;
  1311. InitializeUI();
  1312. }
  1313. /// <summary>
  1314. /// 上一步
  1315. /// </summary>
  1316. /// <param name="sender"></param>
  1317. /// <param name="e"></param>
  1318. private void button6_Click(object sender, EventArgs e)
  1319. {
  1320. step--;
  1321. if (step == 1)
  1322. {
  1323. if (this.panel2.Visible || this.groupBox4.Visible)
  1324. {
  1325. this.groupBox3.Width = this.groupBox3.Width + this.groupBox4.Width + 3;
  1326. }
  1327. this.panel2.Visible = false;
  1328. this.groupBox4.Visible = false;
  1329. this.groupBox5.Visible = false;
  1330. }
  1331. InitializeUI();
  1332. }
  1333. /// <summary>
  1334. /// 初始化UI
  1335. /// </summary>
  1336. private void InitializeUI() {
  1337. if (step == 1) {
  1338. this.label1.Visible = false;
  1339. this.panel1.Visible = false;
  1340. this.label7.Visible = false;
  1341. this.label24.Visible = false;
  1342. this.numericUpDown1.Visible = false;
  1343. this.numericUpDown3.Visible = false;
  1344. this.button7.Visible = false;
  1345. this.button8.Visible = false;
  1346. this.button9.Visible = false;
  1347. this.button5.Enabled = true;
  1348. this.button6.Enabled = false;
  1349. this.button4.Visible = true;
  1350. this.button4.Text = PdnResources.GetString("Menu.Openimage.text");
  1351. this.button1.BackColor = Color.Black;
  1352. this.button1.ForeColor = Color.White;
  1353. this.button2.BackColor = Color.White;
  1354. this.button2.ForeColor = Color.Black;
  1355. this.button3.BackColor = Color.White;
  1356. this.button3.ForeColor = Color.Black;
  1357. }
  1358. if (step == 2) {
  1359. this.label1.Visible = true;
  1360. this.panel1.Visible = true;
  1361. this.label7.Visible = true;
  1362. this.label24.Visible = true;
  1363. this.numericUpDown1.Visible = true;
  1364. this.numericUpDown3.Visible = true;
  1365. this.button7.Visible = true;
  1366. this.button8.Visible = true;
  1367. this.button9.Visible = true;
  1368. this.button6.Enabled = true;
  1369. this.button5.Enabled = true;
  1370. this.panel2.Visible = true;
  1371. this.groupBox4.Visible = false;
  1372. this.groupBox5.Visible = false;
  1373. this.button4.Visible = false;
  1374. this.button4.Text = PdnResources.GetString("Menu.Openimage.text");
  1375. this.button2.BackColor = Color.Black;
  1376. this.button2.ForeColor = Color.White;
  1377. this.button1.BackColor = Color.White;
  1378. this.button1.ForeColor = Color.Black;
  1379. this.button3.BackColor = Color.White;
  1380. this.button3.ForeColor = Color.Black;
  1381. }
  1382. if (step == 3) {
  1383. this.label1.Visible = false;
  1384. this.panel1.Visible = false;
  1385. this.label7.Visible = false;
  1386. this.label24.Visible = false;
  1387. this.numericUpDown1.Visible = false;
  1388. this.numericUpDown3.Visible = false;
  1389. this.button7.Visible = false;
  1390. this.button8.Visible = false;
  1391. this.button9.Visible = false;
  1392. this.button6.Enabled = true;
  1393. this.button5.Enabled = false;
  1394. this.button4.Visible = true;
  1395. this.button4.Text = PdnResources.GetString("Menu.Savetheruler.text");
  1396. this.panel2.Visible = false;
  1397. this.groupBox4.Visible = true;
  1398. this.groupBox5.Visible = true;
  1399. this.button3.BackColor = Color.Black;
  1400. this.button3.ForeColor = Color.White;
  1401. this.button1.BackColor = Color.White;
  1402. this.button1.ForeColor = Color.Black;
  1403. this.button2.BackColor = Color.White;
  1404. this.button2.ForeColor = Color.Black;
  1405. }
  1406. }
  1407. /// <summary>
  1408. /// 初始化hint提示信息
  1409. /// </summary>
  1410. private void InitializeHint()
  1411. {
  1412. SystemLayer.SafeNativeMethods.SetCueText(this.textBox1, PdnResources.GetString("Menu.Pleaseenterarulername.text"));
  1413. SystemLayer.SafeNativeMethods.SetCueText(this.textBox2, PdnResources.GetString("Menu.Pleaseenterthemagnification.text"));
  1414. SystemLayer.SafeNativeMethods.SetCueText(this.textBox4, PdnResources.GetString("Menu.Pleaseinputimageresolution.Text"));
  1415. SystemLayer.SafeNativeMethods.SetCueText(this.textBox5, PdnResources.GetString("Menu.Pleaseenterthephysicallength.text"));
  1416. SystemLayer.SafeNativeMethods.SetCueText(this.textBox6, PdnResources.GetString("Menu.Pixellength.text"));
  1417. SystemLayer.SafeNativeMethods.SetCueText(this.textBox7, PdnResources.GetString("Menu.Pleaseentetionchanger.text"));
  1418. SystemLayer.SafeNativeMethods.SetCueText(this.textBox8, PdnResources.GetString("Menu.Pleaseentertheinterface.text"));
  1419. SystemLayer.SafeNativeMethods.SetCueText(this.textBox9, PdnResources.GetString("Menu.Pleaseentertheeyepiece.text"));
  1420. SystemLayer.SafeNativeMethods.SetCueText(this.textBox10, PdnResources.GetString("Menu.Pleaseenterthecamera.text"));
  1421. SystemLayer.SafeNativeMethods.SetCueText(this.textBox11, PdnResources.GetString("Menu.Pleaseenterobjectlens.text"));
  1422. SystemLayer.SafeNativeMethods.SetCueText(this.textBox12, PdnResources.GetString("Menu.Pleaseenterthemicroscope.text"));
  1423. }
  1424. /// <summary>
  1425. /// 第一步
  1426. /// </summary>
  1427. /// <param name="sender"></param>
  1428. /// <param name="e"></param>
  1429. private void button1_Click(object sender, EventArgs e)
  1430. {
  1431. if (this.panel2.Visible || this.groupBox4.Visible)
  1432. {
  1433. this.groupBox3.Width = this.groupBox3.Width + this.groupBox4.Width + 3;
  1434. }
  1435. this.panel2.Visible = false;
  1436. this.groupBox4.Visible = false;
  1437. this.groupBox5.Visible = false;
  1438. step = 1;
  1439. InitializeUI();
  1440. }
  1441. /// <summary>
  1442. /// 第二步
  1443. /// </summary>
  1444. /// <param name="sender"></param>
  1445. /// <param name="e"></param>
  1446. private void button2_Click(object sender, EventArgs e)
  1447. {
  1448. if (bitmap==null) {
  1449. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectrulerimage.Text")+"!");
  1450. return;
  1451. }
  1452. if (!this.panel2.Visible && !this.groupBox4.Visible)
  1453. {
  1454. this.groupBox3.Width = this.groupBox3.Width - this.groupBox4.Width - 3;
  1455. }
  1456. this.panel2.Visible = true;
  1457. this.groupBox4.Visible = false;
  1458. this.groupBox5.Visible = false;
  1459. this.button4.Text = PdnResources.GetString("Menu.Openimage.text");
  1460. step = 2;
  1461. InitializeUI();
  1462. }
  1463. /// <summary>
  1464. /// 第三步
  1465. /// </summary>
  1466. /// <param name="sender"></param>
  1467. /// <param name="e"></param>
  1468. private void button3_Click(object sender, EventArgs e)
  1469. {
  1470. if (bitmap == null)
  1471. {
  1472. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectrulerimage.Text")+"!");
  1473. return;
  1474. }
  1475. if (!this.panel2.Visible && !this.groupBox4.Visible)
  1476. {
  1477. this.groupBox3.Width = this.groupBox3.Width - this.groupBox4.Width - 3;
  1478. }
  1479. this.panel2.Visible = false;
  1480. this.groupBox4.Visible = true;
  1481. this.groupBox5.Visible = true;
  1482. step = 3;
  1483. InitializeUI();
  1484. }
  1485. /// <summary>
  1486. /// 颜色选择
  1487. /// </summary>
  1488. /// <param name="sender"></param>
  1489. /// <param name="e"></param>
  1490. private void panel1_MouseDown(object sender, MouseEventArgs e)
  1491. {
  1492. this.colorsForm1.UserPrimaryColor = ColorBgra.FromColor(this.panel1.BackColor);
  1493. this.colorsForm1.ShowDialog();
  1494. }
  1495. /// <summary>
  1496. /// 水平方向
  1497. /// </summary>
  1498. /// <param name="sender"></param>
  1499. /// <param name="e"></param>
  1500. private void button7_Click(object sender, EventArgs e)
  1501. {
  1502. direction = 1;
  1503. RemoveDocEvent();
  1504. AddPictureBoxEvent();
  1505. }
  1506. /// <summary>
  1507. /// 垂直方向
  1508. /// </summary>
  1509. /// <param name="sender"></param>
  1510. /// <param name="e"></param>
  1511. private void button8_Click(object sender, EventArgs e)
  1512. {
  1513. direction = 2;
  1514. RemoveDocEvent();
  1515. AddPictureBoxEvent();
  1516. }
  1517. /// <summary>
  1518. /// 任意方向
  1519. /// </summary>
  1520. /// <param name="sender"></param>
  1521. /// <param name="e"></param>
  1522. private void button9_Click(object sender, EventArgs e)
  1523. {
  1524. direction = 3;
  1525. RemoveDocEvent();
  1526. AddPictureBoxEvent();
  1527. }
  1528. /// <summary>
  1529. /// 添加事件
  1530. /// </summary>
  1531. private void AddPictureBoxEvent()
  1532. {
  1533. this.documentWorkspace.panel.MouseDown += new MouseEventHandler(this.BoxMouseDownHandler);
  1534. this.documentWorkspace.panel.MouseMove += new MouseEventHandler(this.BoxMouseMoveHandler);
  1535. this.documentWorkspace.panel.MouseUp += new MouseEventHandler(this.BoxMouseUpHandler);
  1536. this.documentWorkspace.panel.Paint += new PaintEventHandler(this.BoxPaintHandler);
  1537. }
  1538. /// <summary>
  1539. /// 绘制事件
  1540. /// </summary>
  1541. /// <param name="sender"></param>
  1542. /// <param name="e"></param>
  1543. private void BoxPaintHandler(object sender, PaintEventArgs e)
  1544. {
  1545. if (startPoint!=null && endPoint!=null)
  1546. {
  1547. Rectangle rc = this.documentWorkspace.panel.ClientRectangle;
  1548. int width1 = (int)(this.documentWorkspace.CompositionSurface.Width * this.documentWorkspace.ScaleFactor.Ratio);
  1549. int height1 = (int)(this.documentWorkspace.CompositionSurface.Height * this.documentWorkspace.ScaleFactor.Ratio);
  1550. int x = (rc.Width < width1) ? this.documentWorkspace.panel.AutoScrollPosition.X : (rc.Width - width1) / 2;
  1551. int y = (rc.Height < height1) ? this.documentWorkspace.panel.AutoScrollPosition.Y : (rc.Height - height1) / 2;
  1552. double length = BasicCalculationHelper.GetDistance(startPoint, endPoint, 2);
  1553. e.Graphics.TranslateTransform(x, y);
  1554. e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio);
  1555. Pen linePen = new Pen(this.panel1.BackColor);
  1556. brush = new SolidBrush(this.panel1.BackColor);
  1557. linePen.Width = width;
  1558. linePen.CustomStartCap = HookCap;
  1559. linePen.CustomEndCap = HookCap;
  1560. e.Graphics.DrawLine(linePen, startPoint, endPoint);
  1561. linePen.Dispose();
  1562. //参考下,然后绘制带角度的文字https://www.jianshu.com/p/404ed85887e6
  1563. if (length > 0)
  1564. {
  1565. //计算需要旋转的角度
  1566. double angle = BasicCalculationHelper.Angle(startPoint, endPoint, new System.Drawing.Point(startPoint.X, endPoint.Y));
  1567. //原始旋转矩阵
  1568. Matrix mtxSave = e.Graphics.Transform;
  1569. Matrix matrix = e.Graphics.Transform;
  1570. matrix.RotateAt((float)angle, new PointF(startPoint.X, startPoint.Y));
  1571. e.Graphics.Transform = matrix;
  1572. e.Graphics.DrawString(length + "px", font, brush, startPoint.X, startPoint.Y);
  1573. //还原为原始旋转矩阵
  1574. e.Graphics.Transform = mtxSave;
  1575. this.textBox6.Text = length.ToString();//将像素长度传递至第三步
  1576. }
  1577. e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio);
  1578. e.Graphics.TranslateTransform(-x, -y);
  1579. }
  1580. }
  1581. private void BoxMouseUpHandler(object sender, MouseEventArgs e)
  1582. {
  1583. this.pressFlag = false;
  1584. if (e.Button == MouseButtons.Left)
  1585. direction = 0;
  1586. }
  1587. private void BoxMouseMoveHandler(object sender, MouseEventArgs e)
  1588. {
  1589. if (this.bitmap != null)
  1590. {
  1591. this.SetImageAndData(this.documentWorkspace.CalcPixelPoint(e.Location));
  1592. }
  1593. if (this.pressFlag && direction > 0 && e.Button == MouseButtons.Left) {
  1594. System.Drawing.Point point = e.Location;
  1595. if (direction == 1)
  1596. {
  1597. point.Y = y;
  1598. }
  1599. else if (direction == 2)
  1600. {
  1601. point.X = x;
  1602. }
  1603. this.endPoint = this.documentWorkspace.GetScalePoint(point);
  1604. this.documentWorkspace.Refresh();
  1605. }
  1606. }
  1607. private void numericUpDown2_ValueChanged(object sender, EventArgs e)
  1608. {
  1609. if (mat != null)
  1610. {
  1611. scale = (int)this.numericUpDown2.Value;
  1612. this.trackBar1.Value = scale;
  1613. }
  1614. }
  1615. private void trackBar1_ValueChanged(object sender, EventArgs e)
  1616. {
  1617. if (mat != null)
  1618. {
  1619. scale = this.trackBar1.Value;
  1620. this.numericUpDown2.Value = this.trackBar1.Value;
  1621. }
  1622. }
  1623. private void numericUpDown3_ValueChanged(object sender, EventArgs e)
  1624. {
  1625. font = new Font("常规", (int)this.numericUpDown3.Value);
  1626. this.documentWorkspace.Refresh();
  1627. }
  1628. private void pictureBox1_Paint(object sender, PaintEventArgs e)
  1629. {
  1630. e.Graphics.DrawLine(new Pen(color), 0, 50, 100, 50);
  1631. e.Graphics.DrawLine(new Pen(color), 50, 0, 50, 100);
  1632. e.Graphics.DrawEllipse(new Pen(color), new Rectangle(25, 25, 50, 50));
  1633. }
  1634. private void BoxMouseDownHandler(object sender, MouseEventArgs e)
  1635. {
  1636. this.pressFlag = true;
  1637. if (direction > 0 && e.Button == MouseButtons.Left) {
  1638. x = e.Location.X;
  1639. y = e.Location.Y;
  1640. startPoint = endPoint = this.documentWorkspace.GetScalePoint(e.Location);
  1641. }
  1642. }
  1643. private void numericUpDown1_ValueChanged(object sender, EventArgs e)
  1644. {
  1645. this.width = (int)this.numericUpDown1.Value;
  1646. this.documentWorkspace.Refresh();
  1647. }
  1648. private void RemoveDocEvent()
  1649. {
  1650. this.documentWorkspace.DocumentMouseUp -= new MouseEventHandler(this.MouseUpHandler);
  1651. this.documentWorkspace.DocumentMouseMove -= new MouseEventHandler(this.MouseMoveHandler);
  1652. this.documentWorkspace.DocumentMouseDown -= new MouseEventHandler(this.MouseDownHandler);
  1653. }
  1654. /// <summary>
  1655. /// 设置像素跟踪
  1656. /// </summary>
  1657. /// <param name="point"></param>
  1658. public void SetImageAndData(System.Drawing.Point point)
  1659. {
  1660. if (this.documentWorkspace != null)
  1661. {
  1662. if (this.documentWorkspace.CompositionSurface != null)
  1663. {
  1664. scale = int.Parse(this.numericUpDown2.Value.ToString());
  1665. if (mat == null)
  1666. {
  1667. mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.documentWorkspace.CompositionSurface.CreateAliasedBitmap());
  1668. Cv2.Resize(mat, bmat, new OpenCvSharp.Size(mat.Width * scale, mat.Height * scale));
  1669. Mat temp = new Mat(new OpenCvSharp.Size(bmat.Width + 100, bmat.Height + 100), bmat.Type());
  1670. Cv2.CopyMakeBorder(bmat, temp, 50, 50, 50, 50, BorderTypes.Constant, Scalar.All(255));
  1671. bmat = temp;
  1672. }
  1673. if (point.Y < 0) point.Y = 0;
  1674. if (point.X < 0) point.X = 0;
  1675. this.label11.Text = "X=" + point.X.ToString();
  1676. this.label10.Text = "Y=" + point.Y.ToString();
  1677. if (point.X< mat.Width && point.Y < mat.Height)
  1678. {
  1679. bgr = mat.At<Vec3b>(point.Y, point.X);
  1680. this.label8.Text = "R=" + bgr[2];
  1681. this.label2.Text = "G=" + bgr[1];
  1682. this.label3.Text = "B=" + bgr[0];
  1683. BaseTools.RgbToHsv(bgr, out h, out s, out v);
  1684. this.label4.Text = "H=" + (int)(h / 2);
  1685. this.label5.Text = "S=" + (int)(s * 255);
  1686. this.label6.Text = "V=" + (int)(v * 255);
  1687. //设置源图像ROI
  1688. Rect roi = new Rect(point.X, point.Y, 100, 100);//首先要用个rect确定我们的兴趣区域在哪
  1689. ImageROI = new Mat(bmat, roi);
  1690. //按缩放比例截取小图像
  1691. Rect roi1 = new Rect((100 - 100 / scale) / 2, (100 - 100 / scale) / 2, 100 / scale, 100 / scale);
  1692. ImageROI = new Mat(ImageROI, roi1);
  1693. //按固定宽高放大图像
  1694. Cv2.Resize(ImageROI, ImageROI, new OpenCvSharp.Size(100, 100));
  1695. this.pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(ImageROI);
  1696. }
  1697. }
  1698. }
  1699. }
  1700. }
  1701. }