123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- namespace PaintDotNet.Binarization
- {
- /// <summary>
- /// 添加相的dialog
- /// </summary>
- internal class AddPhaseDialog : Form
- {
- private Button button2;
- private Label label1;
- private Label label2;
- private TextBox textBox1;
- private Panel panel1;
- private Button button1;
- private ColorsForm colorsFormGrid;
- private PhaseExtractDialog phaseExtractDialog;
- private int color = 0;
- private bool editFlag = false;
- public AddPhaseDialog(PhaseExtractDialog phaseExtractDialog, string name, Color color, bool edit)
- {
- InitializeComponent();
- InitializeLanguageText();
- this.phaseExtractDialog = phaseExtractDialog;
- this.editFlag = edit;
- //
- //初始化色板
- //
- this.colorsFormGrid = new ColorsForm();
- this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
- this.textBox1.Text = name;
- this.panel1.BackColor = color;
- this.color = color.ToArgb();
- }
- private void InitializeLanguageText()
- {
- this.Text = PdnResources.GetString("Menu.Phasemaintenance.text");
- this.button1.Text = PdnResources.GetString("Menu.ensure.text");
- this.button2.Text = PdnResources.GetString("Menu.cancel.text");
- this.label1.Text = PdnResources.GetString("Menu.Phasename.text") + ":";
- this.label2.Text = PdnResources.GetString("Menu.Phasecolor.text") + ":";
- }
- private void InitializeComponent()
- {
- this.button1 = new System.Windows.Forms.Button();
- this.button2 = new System.Windows.Forms.Button();
- this.label1 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.textBox1 = new System.Windows.Forms.TextBox();
- this.panel1 = new System.Windows.Forms.Panel();
- this.SuspendLayout();
- //
- // button1
- //
- this.button1.Location = new System.Drawing.Point(148, 111);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(75, 23);
- this.button1.TabIndex = 0;
- this.button1.Text = "确定";
- this.button1.UseVisualStyleBackColor = true;
- this.button1.Click += new System.EventHandler(this.button1_Click);
- //
- // button2
- //
- this.button2.Location = new System.Drawing.Point(229, 111);
- this.button2.Name = "button2";
- this.button2.Size = new System.Drawing.Size(75, 23);
- this.button2.TabIndex = 1;
- this.button2.Text = "取消";
- this.button2.UseVisualStyleBackColor = true;
- this.button2.Click += new System.EventHandler(this.button2_Click);
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.Location = new System.Drawing.Point(12, 32);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(41, 12);
- this.label1.TabIndex = 2;
- this.label1.Text = "相名称";
- //
- // label2
- //
- this.label2.AutoSize = true;
- this.label2.Location = new System.Drawing.Point(14, 72);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(41, 12);
- this.label2.TabIndex = 3;
- this.label2.Text = "相颜色";
- //
- // textBox1
- //
- this.textBox1.Location = new System.Drawing.Point(72, 28);
- this.textBox1.Name = "textBox1";
- this.textBox1.Size = new System.Drawing.Size(232, 21);
- this.textBox1.TabIndex = 4;
- //
- // panel1
- //
- this.panel1.BackColor = System.Drawing.Color.White;
- this.panel1.Location = new System.Drawing.Point(72, 67);
- this.panel1.Name = "panel1";
- this.panel1.Size = new System.Drawing.Size(232, 21);
- this.panel1.TabIndex = 5;
- this.panel1.Click += new System.EventHandler(this.panel1_Click);
- //
- // AddPhaseDialog
- //
- this.ClientSize = new System.Drawing.Size(316, 156);
- this.Controls.Add(this.panel1);
- this.Controls.Add(this.textBox1);
- this.Controls.Add(this.label2);
- this.Controls.Add(this.label1);
- this.Controls.Add(this.button2);
- this.Controls.Add(this.button1);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
- this.Name = "AddPhaseDialog";
- this.Text = "相维护";
- this.ResumeLayout(false);
- this.PerformLayout();
- }
- /// <summary>
- /// 取消
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button2_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- /// <summary>
- /// 确定
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button1_Click(object sender, EventArgs e)
- {
- string name = this.textBox1.Text;
- if (String.IsNullOrWhiteSpace(name))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseinputphasname.Text"));
- return;
- }
- if (this.color == 0)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleasechoosethecolorofphase.text"));
- return;
- }
- if (this.editFlag)
- {
- this.phaseExtractDialog.UpdatePhase(name, color);
- }
- else
- {
- this.phaseExtractDialog.AddPhase(name, color);
- }
-
- this.Close();
- }
- /// <summary>
- /// 颜色选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void panel1_Click(object sender, EventArgs e)
- {
- this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(this.panel1.BackColor);
- this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
- this.colorsFormGrid.ShowDialog();
- }
- /// <summary>
- /// Panel2的调色板颜色改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void gridColorChanged(object sender, EventArgs e)
- {
- Color color1 = this.colorsFormGrid.UserPrimaryColor.ToColor();
- //更改背景色,触发事件
- this.panel1.BackColor = color1;
- //设置当前相颜色
- this.color = color1.ToArgb();
- //关闭色板
- this.colorsFormGrid.Close();
- }
- }
- }
|