AddPhaseDialog.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. namespace PaintDotNet.Binarization
  5. {
  6. /// <summary>
  7. /// 添加相的dialog
  8. /// </summary>
  9. internal class AddPhaseDialog : Form
  10. {
  11. private Button button2;
  12. private Label label1;
  13. private Label label2;
  14. private TextBox textBox1;
  15. private Panel panel1;
  16. private Button button1;
  17. private ColorsForm colorsFormGrid;
  18. private PhaseExtractDialog phaseExtractDialog;
  19. private int color = 0;
  20. private bool editFlag = false;
  21. public AddPhaseDialog(PhaseExtractDialog phaseExtractDialog, string name, Color color, bool edit)
  22. {
  23. InitializeComponent();
  24. InitializeLanguageText();
  25. this.phaseExtractDialog = phaseExtractDialog;
  26. this.editFlag = edit;
  27. //
  28. //初始化色板
  29. //
  30. this.colorsFormGrid = new ColorsForm();
  31. this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
  32. this.textBox1.Text = name;
  33. this.panel1.BackColor = color;
  34. this.color = color.ToArgb();
  35. }
  36. private void InitializeLanguageText()
  37. {
  38. this.Text = PdnResources.GetString("Menu.Phasemaintenance.text");
  39. this.button1.Text = PdnResources.GetString("Menu.ensure.text");
  40. this.button2.Text = PdnResources.GetString("Menu.cancel.text");
  41. this.label1.Text = PdnResources.GetString("Menu.Phasename.text") + ":";
  42. this.label2.Text = PdnResources.GetString("Menu.Phasecolor.text") + ":";
  43. }
  44. private void InitializeComponent()
  45. {
  46. this.button1 = new System.Windows.Forms.Button();
  47. this.button2 = new System.Windows.Forms.Button();
  48. this.label1 = new System.Windows.Forms.Label();
  49. this.label2 = new System.Windows.Forms.Label();
  50. this.textBox1 = new System.Windows.Forms.TextBox();
  51. this.panel1 = new System.Windows.Forms.Panel();
  52. this.SuspendLayout();
  53. //
  54. // button1
  55. //
  56. this.button1.Location = new System.Drawing.Point(148, 111);
  57. this.button1.Name = "button1";
  58. this.button1.Size = new System.Drawing.Size(75, 23);
  59. this.button1.TabIndex = 0;
  60. this.button1.Text = "确定";
  61. this.button1.UseVisualStyleBackColor = true;
  62. this.button1.Click += new System.EventHandler(this.button1_Click);
  63. //
  64. // button2
  65. //
  66. this.button2.Location = new System.Drawing.Point(229, 111);
  67. this.button2.Name = "button2";
  68. this.button2.Size = new System.Drawing.Size(75, 23);
  69. this.button2.TabIndex = 1;
  70. this.button2.Text = "取消";
  71. this.button2.UseVisualStyleBackColor = true;
  72. this.button2.Click += new System.EventHandler(this.button2_Click);
  73. //
  74. // label1
  75. //
  76. this.label1.AutoSize = true;
  77. this.label1.Location = new System.Drawing.Point(12, 32);
  78. this.label1.Name = "label1";
  79. this.label1.Size = new System.Drawing.Size(41, 12);
  80. this.label1.TabIndex = 2;
  81. this.label1.Text = "相名称";
  82. //
  83. // label2
  84. //
  85. this.label2.AutoSize = true;
  86. this.label2.Location = new System.Drawing.Point(14, 72);
  87. this.label2.Name = "label2";
  88. this.label2.Size = new System.Drawing.Size(41, 12);
  89. this.label2.TabIndex = 3;
  90. this.label2.Text = "相颜色";
  91. //
  92. // textBox1
  93. //
  94. this.textBox1.Location = new System.Drawing.Point(72, 28);
  95. this.textBox1.Name = "textBox1";
  96. this.textBox1.Size = new System.Drawing.Size(232, 21);
  97. this.textBox1.TabIndex = 4;
  98. //
  99. // panel1
  100. //
  101. this.panel1.BackColor = System.Drawing.Color.White;
  102. this.panel1.Location = new System.Drawing.Point(72, 67);
  103. this.panel1.Name = "panel1";
  104. this.panel1.Size = new System.Drawing.Size(232, 21);
  105. this.panel1.TabIndex = 5;
  106. this.panel1.Click += new System.EventHandler(this.panel1_Click);
  107. //
  108. // AddPhaseDialog
  109. //
  110. this.ClientSize = new System.Drawing.Size(316, 156);
  111. this.Controls.Add(this.panel1);
  112. this.Controls.Add(this.textBox1);
  113. this.Controls.Add(this.label2);
  114. this.Controls.Add(this.label1);
  115. this.Controls.Add(this.button2);
  116. this.Controls.Add(this.button1);
  117. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  118. this.Name = "AddPhaseDialog";
  119. this.Text = "相维护";
  120. this.ResumeLayout(false);
  121. this.PerformLayout();
  122. }
  123. /// <summary>
  124. /// 取消
  125. /// </summary>
  126. /// <param name="sender"></param>
  127. /// <param name="e"></param>
  128. private void button2_Click(object sender, EventArgs e)
  129. {
  130. this.Close();
  131. }
  132. /// <summary>
  133. /// 确定
  134. /// </summary>
  135. /// <param name="sender"></param>
  136. /// <param name="e"></param>
  137. private void button1_Click(object sender, EventArgs e)
  138. {
  139. string name = this.textBox1.Text;
  140. if (String.IsNullOrWhiteSpace(name))
  141. {
  142. MessageBox.Show(PdnResources.GetString("Menu.Pleaseinputphasname.Text"));
  143. return;
  144. }
  145. if (this.color == 0)
  146. {
  147. MessageBox.Show(PdnResources.GetString("Menu.Pleasechoosethecolorofphase.text"));
  148. return;
  149. }
  150. if (this.editFlag)
  151. {
  152. this.phaseExtractDialog.UpdatePhase(name, color);
  153. }
  154. else
  155. {
  156. this.phaseExtractDialog.AddPhase(name, color);
  157. }
  158. this.Close();
  159. }
  160. /// <summary>
  161. /// 颜色选择
  162. /// </summary>
  163. /// <param name="sender"></param>
  164. /// <param name="e"></param>
  165. private void panel1_Click(object sender, EventArgs e)
  166. {
  167. this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(this.panel1.BackColor);
  168. this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
  169. this.colorsFormGrid.ShowDialog();
  170. }
  171. /// <summary>
  172. /// Panel2的调色板颜色改变
  173. /// </summary>
  174. /// <param name="sender"></param>
  175. /// <param name="e"></param>
  176. private void gridColorChanged(object sender, EventArgs e)
  177. {
  178. Color color1 = this.colorsFormGrid.UserPrimaryColor.ToColor();
  179. //更改背景色,触发事件
  180. this.panel1.BackColor = color1;
  181. //设置当前相颜色
  182. this.color = color1.ToArgb();
  183. //关闭色板
  184. this.colorsFormGrid.Close();
  185. }
  186. }
  187. }