using PaintDotNet.Base.SettingModel; using PaintDotNet.Base.CommTool; using System; using System.Collections; using System.Drawing; using System.IO; using System.Windows.Forms; namespace PaintDotNet.DedicatedAnalysis { public partial class GuideStyleSettingsDialog : Form { #region 控件 private GroupBox groupBox2; private GroupBox groupBox3; private Button button1; private Button button2; private Label label6; private Label label5; private Label label4; private Label label3; private Label label2; private Label label1; private Panel panel1; private Panel panel2; private GroupBox groupBox1; private NumericUpDown numericUpDown2; private NumericUpDown numericUpDown1; private NumericUpDown numericUpDown4; private NumericUpDown numericUpDown3; private ComboBox comboBox1; private void InitializeLanguageText() { this.groupBox1.Text = PdnResources.GetString("Menu.operation.text"); this.button2.Text = PdnResources.GetString("CommonAction.Save"); this.button1.Text = PdnResources.GetString("Menu.File.Close.Text"); this.groupBox2.Text = PdnResources.GetString("Menu.Tools.AuxiliaryLine.Text"); this.label6.Text = PdnResources.GetString("Menu.size.text") + ":"; this.label5.Text = PdnResources.GetString("Menu.Font.text") + ":"; this.label4.Text = PdnResources.GetString("Menu.spacing.text") + ":"; this.label3.Text = PdnResources.GetString("Menu.Linewidth.text") + ":"; this.label2.Text = PdnResources.GetString("Menu.color.text") + ":"; this.label1.Text = PdnResources.GetString("Menu.Numberof.text") + ":"; this.groupBox3.Text = PdnResources.GetString("Menu.Preview.text"); this.Text = PdnResources.GetString("Menu.Auxiliarylinestylesettings.text"); } private void InitializeComponent() { this.groupBox1 = new System.Windows.Forms.GroupBox(); this.button2 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.numericUpDown4 = new System.Windows.Forms.NumericUpDown(); this.numericUpDown3 = new System.Windows.Forms.NumericUpDown(); this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); this.panel2 = new System.Windows.Forms.Panel(); this.label6 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.panel1 = new System.Windows.Forms.Panel(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); this.groupBox3.SuspendLayout(); this.SuspendLayout(); // // groupBox1 // this.groupBox1.Controls.Add(this.button2); this.groupBox1.Controls.Add(this.button1); this.groupBox1.Location = new System.Drawing.Point(11, 12); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(320, 54); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; // // button2 // this.button2.Location = new System.Drawing.Point(228, 15); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(70, 28); this.button2.TabIndex = 1; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // // button1 // this.button1.Location = new System.Drawing.Point(139, 15); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(70, 28); this.button1.TabIndex = 0; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // groupBox2 // this.groupBox2.Controls.Add(this.comboBox1); this.groupBox2.Controls.Add(this.numericUpDown4); this.groupBox2.Controls.Add(this.numericUpDown3); this.groupBox2.Controls.Add(this.numericUpDown2); this.groupBox2.Controls.Add(this.numericUpDown1); this.groupBox2.Controls.Add(this.panel2); this.groupBox2.Controls.Add(this.label6); this.groupBox2.Controls.Add(this.label5); this.groupBox2.Controls.Add(this.label4); this.groupBox2.Controls.Add(this.label3); this.groupBox2.Controls.Add(this.label2); this.groupBox2.Controls.Add(this.label1); this.groupBox2.Location = new System.Drawing.Point(12, 72); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(319, 145); this.groupBox2.TabIndex = 1; this.groupBox2.TabStop = false; // // comboBox1 // this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBox1.FormattingEnabled = true; this.comboBox1.Location = new System.Drawing.Point(214, 65); this.comboBox1.Name = "comboBox1"; this.comboBox1.Size = new System.Drawing.Size(82, 20); this.comboBox1.TabIndex = 17; this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); // // numericUpDown4 // this.numericUpDown4.Location = new System.Drawing.Point(214, 27); this.numericUpDown4.Maximum = new decimal(new int[] { 99999, 0, 0, 0}); this.numericUpDown4.Minimum = new decimal(new int[] { 1, 0, 0, 0}); this.numericUpDown4.Name = "numericUpDown4"; this.numericUpDown4.Size = new System.Drawing.Size(82, 21); this.numericUpDown4.TabIndex = 16; this.numericUpDown4.Value = new decimal(new int[] { 1, 0, 0, 0}); this.numericUpDown4.ValueChanged += new System.EventHandler(this.numericUpDown4_ValueChanged); // // numericUpDown3 // this.numericUpDown3.Location = new System.Drawing.Point(214, 104); this.numericUpDown3.Minimum = new decimal(new int[] { 1, 0, 0, 0}); this.numericUpDown3.Name = "numericUpDown3"; this.numericUpDown3.Size = new System.Drawing.Size(82, 21); this.numericUpDown3.TabIndex = 15; this.numericUpDown3.Value = new decimal(new int[] { 1, 0, 0, 0}); this.numericUpDown3.ValueChanged += new System.EventHandler(this.numericUpDown3_ValueChanged); // // numericUpDown2 // this.numericUpDown2.Location = new System.Drawing.Point(57, 104); this.numericUpDown2.Minimum = new decimal(new int[] { 1, 0, 0, 0}); this.numericUpDown2.Name = "numericUpDown2"; this.numericUpDown2.Size = new System.Drawing.Size(82, 21); this.numericUpDown2.TabIndex = 14; this.numericUpDown2.Value = new decimal(new int[] { 1, 0, 0, 0}); this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged); // // numericUpDown1 // this.numericUpDown1.Location = new System.Drawing.Point(57, 27); this.numericUpDown1.Maximum = new decimal(new int[] { 5, 0, 0, 0}); this.numericUpDown1.Minimum = new decimal(new int[] { 3, 0, 0, 0}); this.numericUpDown1.Name = "numericUpDown1"; this.numericUpDown1.Size = new System.Drawing.Size(82, 21); this.numericUpDown1.TabIndex = 13; this.numericUpDown1.Value = new decimal(new int[] { 3, 0, 0, 0}); this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged); // // panel2 // this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.panel2.Location = new System.Drawing.Point(58, 65); this.panel2.Name = "panel2"; this.panel2.Size = new System.Drawing.Size(81, 21); this.panel2.TabIndex = 12; this.panel2.BackColorChanged += new System.EventHandler(this.panel2_BackColorChanged); this.panel2.Click += new System.EventHandler(this.panel2_Click); // // label6 // this.label6.AutoSize = true; this.label6.Location = new System.Drawing.Point(180, 107); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(41, 12); this.label6.TabIndex = 5; // // label5 // this.label5.AutoSize = true; this.label5.Location = new System.Drawing.Point(180, 69); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(41, 12); this.label5.TabIndex = 4; // // label4 // this.label4.AutoSize = true; this.label4.Location = new System.Drawing.Point(180, 31); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(41, 12); this.label4.TabIndex = 3; // // label3 // this.label3.AutoSize = true; this.label3.Location = new System.Drawing.Point(18, 107); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(41, 12); this.label3.TabIndex = 2; // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(18, 69); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(41, 12); this.label2.TabIndex = 1; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(18, 31); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(41, 12); this.label1.TabIndex = 0; // // groupBox3 // this.groupBox3.Controls.Add(this.panel1); this.groupBox3.Location = new System.Drawing.Point(12, 223); this.groupBox3.Name = "groupBox3"; this.groupBox3.Size = new System.Drawing.Size(319, 116); this.groupBox3.TabIndex = 1; this.groupBox3.TabStop = false; // // panel1 // this.panel1.Location = new System.Drawing.Point(27, 17); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(270, 88); this.panel1.TabIndex = 0; this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint); // // GuideStyleSettingsDialog // this.ClientSize = new System.Drawing.Size(343, 351); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.MaximizeBox = false; this.MaximumSize = new System.Drawing.Size(359, 390); this.MinimizeBox = false; this.MinimumSize = new System.Drawing.Size(359, 390); this.Name = "GuideStyleSettingsDialog"; this.ShowInTaskbar = false; this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); this.groupBox3.ResumeLayout(false); this.ResumeLayout(false); } #endregion /// /// 字体列表 /// private ArrayList fontsItems = new ArrayList(); /// /// 调色板 /// private PaintDotNet.ColorsForm colorsForm; public GuideStyleSettingsDialog(bool lineChange) { InitializeComponent(); InitializeLanguageText(); InitializeData(); this.numericUpDown1.Enabled = lineChange; //调色板 this.colorsForm = new ColorsForm(); this.colorsForm.StartPosition = FormStartPosition.CenterScreen; this.colorsForm.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged); } /// /// 初始化数据 /// private void InitializeData() { this.fontsItems.Clear(); //绑定字体数据 System.Drawing.Text.InstalledFontCollection fonts = new System.Drawing.Text.InstalledFontCollection(); foreach (FontFamily fontFamily in fonts.Families) { fontsItems.Add(fontFamily.Name); } this.comboBox1.DataSource = fontsItems; CompoundRatioStyleModel compoundRatioStyleModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GuideStyle.xml", FileMode.Open)); if (compoundRatioStyleModel.guideStyle != null) { this.numericUpDown1.Value = compoundRatioStyleModel.guideStyle.linesNumber; this.panel2.BackColor = Color.FromArgb(compoundRatioStyleModel.guideStyle.lineColor); this.numericUpDown2.Value = compoundRatioStyleModel.guideStyle.lineWidth; this.numericUpDown4.Value = compoundRatioStyleModel.guideStyle.spacing; this.comboBox1.Text = compoundRatioStyleModel.guideStyle.font; this.numericUpDown3.Value = compoundRatioStyleModel.guideStyle.fontSize; } } /// /// 页面关闭 /// /// /// private void button1_Click(object sender, EventArgs e) { this.Close(); } private void colorsFormUserPrimaryColorChanged(object sender, ColorEventArgs ce) { } private void panel2_Click(object sender, EventArgs e) { this.colorsForm.UserPrimaryColor = ColorBgra.FromColor(this.panel2.BackColor); this.colorsForm.setSaveBtn_Click(new System.EventHandler(this.panel2Changed)); this.colorsForm.ShowDialog(); } private void panel2Changed(object sender, EventArgs e) { this.panel2.BackColor = this.colorsForm.UserPrimaryColor.ToColor(); this.colorsForm.Close(); } /// /// 保存按钮 /// /// /// private void button2_Click(object sender, EventArgs e) { CompoundRatioStyleModel compoundRatioStyleModelOld = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GuideStyle.xml", FileMode.Open)); CompoundRatioStyleModel compoundRatioStyleModel = new CompoundRatioStyleModel(); compoundRatioStyleModel.guideStyle = new CompoundRatioStyleModel.GuideStyle(); compoundRatioStyleModel.guideStyle.font = this.comboBox1.Text; compoundRatioStyleModel.guideStyle.fontSize = Convert.ToInt32(numericUpDown3.Value); compoundRatioStyleModel.guideStyle.lineColor = Convert.ToInt32(this.panel2.BackColor.ToArgb()); compoundRatioStyleModel.guideStyle.linesNumber = Convert.ToInt32(numericUpDown1.Value); compoundRatioStyleModel.guideStyle.lineWidth = Convert.ToInt32(numericUpDown2.Value); compoundRatioStyleModel.guideStyle.spacing = Convert.ToInt32(numericUpDown4.Value); //以下保存xml文件信息 string stageModelXml = XmlSerializeHelper.XmlSerialize(compoundRatioStyleModel); string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GuideStyle.xml"; FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create); RecombinationRateDialog recombinationRateDialog = (RecombinationRateDialog)this.Owner; recombinationRateDialog.RefreshPanel(); if (compoundRatioStyleModelOld.guideStyle.linesNumber != Convert.ToInt32(numericUpDown1.Value) || compoundRatioStyleModelOld.guideStyle.spacing != Convert.ToInt32(numericUpDown4.Value)) recombinationRateDialog.InitMeasurePoints(); } /// /// 辅助线样式预览 /// /// /// private void panel1_Paint(object sender, PaintEventArgs e) { GuideStylePreview(e.Graphics); } /// /// 辅助线样式预览 /// private void GuideStylePreview(Graphics g) { this.panel1.BackColor = Color.Black; Pen linePen = new Pen(this.panel2.BackColor, Convert.ToInt32(numericUpDown2.Value)); Font textfont = new Font(this.comboBox1.Text, Convert.ToInt32(numericUpDown3.Value)); SizeF size = g.MeasureString("abc", textfont); if(Convert.ToInt32(numericUpDown1.Value) == 3) { g.DrawLine(linePen, new Point(this.panel1.Width / 2 - 90, 0), new Point(this.panel1.Width / 2 - 90, this.panel1.Height)); g.DrawLine(linePen, new Point(this.panel1.Width / 2, 0), new Point(this.panel1.Width / 2, this.panel1.Height)); g.DrawLine(linePen, new Point(this.panel1.Width / 2 + 90, 0), new Point(this.panel1.Width / 2 + 90, this.panel1.Height)); g.DrawString("abc", textfont, new SolidBrush(Color.Red), new PointF(this.panel1.Width / 2 - 90 - size.Width / 2, this.panel1.Height / 2 - size.Height / 2)); g.DrawString("abc", textfont, new SolidBrush(Color.Red), new PointF(this.panel1.Width / 2 - size.Width / 2, this.panel1.Height / 2 - size.Height / 2)); g.DrawString("abc", textfont, new SolidBrush(Color.Red), new PointF(this.panel1.Width / 2 + 90 - size.Width / 2, this.panel1.Height / 2 - size.Height / 2)); } else if (Convert.ToInt32(numericUpDown1.Value) == 4) { g.DrawLine(linePen, new Point(this.panel1.Width / 2 - 105, 0), new Point(this.panel1.Width / 2 - 105, this.panel1.Height)); g.DrawLine(linePen, new Point(this.panel1.Width / 2 - 35, 0), new Point(this.panel1.Width / 2 - 35, this.panel1.Height)); g.DrawLine(linePen, new Point(this.panel1.Width / 2 + 35, 0), new Point(this.panel1.Width / 2 + 35, this.panel1.Height)); g.DrawLine(linePen, new Point(this.panel1.Width / 2 + 105, 0), new Point(this.panel1.Width / 2 + 105, this.panel1.Height)); g.DrawString("abc", textfont, new SolidBrush(Color.Red), new PointF(this.panel1.Width / 2 - 105 - size.Width / 2, this.panel1.Height / 2 - size.Height / 2)); g.DrawString("abc", textfont, new SolidBrush(Color.Red), new PointF(this.panel1.Width / 2 - 35 - size.Width / 2, this.panel1.Height / 2 - size.Height / 2)); g.DrawString("abc", textfont, new SolidBrush(Color.Red), new PointF(this.panel1.Width / 2 + 35 - size.Width / 2, this.panel1.Height / 2 - size.Height / 2)); g.DrawString("abc", textfont, new SolidBrush(Color.Red), new PointF(this.panel1.Width / 2 + 105 - size.Width / 2, this.panel1.Height / 2 - size.Height / 2)); } else if (Convert.ToInt32(numericUpDown1.Value) == 5) { g.DrawLine(linePen, new Point(this.panel1.Width / 2 - 108, 0), new Point(this.panel1.Width / 2 - 108, this.panel1.Height)); g.DrawLine(linePen, new Point(this.panel1.Width / 2 - 54, 0), new Point(this.panel1.Width / 2 - 54, this.panel1.Height)); g.DrawLine(linePen, new Point(this.panel1.Width / 2, 0), new Point(this.panel1.Width / 2, this.panel1.Height)); g.DrawLine(linePen, new Point(this.panel1.Width / 2 + 54, 0), new Point(this.panel1.Width / 2 + 54, this.panel1.Height)); g.DrawLine(linePen, new Point(this.panel1.Width / 2 + 108, 0), new Point(this.panel1.Width / 2 + 108, this.panel1.Height)); g.DrawString("abc", textfont, new SolidBrush(Color.Red), new PointF(this.panel1.Width / 2 - 108 - size.Width / 2, this.panel1.Height / 2 - size.Height / 2)); g.DrawString("abc", textfont, new SolidBrush(Color.Red), new PointF(this.panel1.Width / 2 - 54 - size.Width / 2, this.panel1.Height / 2 - size.Height / 2)); g.DrawString("abc", textfont, new SolidBrush(Color.Red), new PointF(this.panel1.Width / 2 - size.Width / 2, this.panel1.Height / 2 - size.Height / 2)); g.DrawString("abc", textfont, new SolidBrush(Color.Red), new PointF(this.panel1.Width / 2 + 54 - size.Width / 2, this.panel1.Height / 2 - size.Height / 2)); g.DrawString("abc", textfont, new SolidBrush(Color.Red), new PointF(this.panel1.Width / 2 + 108 - size.Width / 2, this.panel1.Height / 2 - size.Height / 2)); } } /// /// 线颜色改变 /// /// /// private void panel2_BackColorChanged(object sender, EventArgs e) { this.panel1.Refresh(); } /// /// 线宽改变 /// /// /// private void numericUpDown2_ValueChanged(object sender, EventArgs e) { this.panel1.Refresh(); } /// /// 线间距改变 /// /// /// private void numericUpDown4_ValueChanged(object sender, EventArgs e) { this.panel1.Refresh(); } /// /// 字体改变 /// /// /// private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { this.panel1.Refresh(); } /// /// 字体大小改变 /// /// /// private void numericUpDown3_ValueChanged(object sender, EventArgs e) { this.panel1.Refresh(); } /// /// 线条数改变 /// /// /// private void numericUpDown1_ValueChanged(object sender, EventArgs e) { this.panel1.Refresh(); } } }