using PaintDotNet.Base.SettingModel; using PaintDotNet.Base.CommTool; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Entity.Core.Metadata.Edm; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Runtime.InteropServices; using PaintDotNet.DedicatedAnalysis.GrainSize; namespace PaintDotNet.DedicatedAnalysis { /// /// 晶粒度(仲裁法)辅助线设置 /// public partial class ArbitrationLawGuideDialog : Form { #region 控件 private GroupBox groupBox2; private GroupBox groupBox3; private Button button1; private Button button2; private Label label3; private Label label2; private Panel panel1; private Panel panel2; private GroupBox groupBox1; private NumericUpDown numericUpDown2; private GroupBox groupBox4; private Button button5; private Button button4; private Button button3; private Label label7; private TextBox textBox1; private ComboBox comboBox1; private DataGridView dataGridView1; #endregion /// /// 字体列表 /// ArrayList fontsItems = new ArrayList(); /// /// 超出尺寸 /// private bool exceed; /// /// 调色板 /// PaintDotNet.ColorsForm colorsForm; /// /// 操作区分(0 :添加 1 :编辑) /// private int operation = -1; /// /// 临时数据 /// private List arrayLists = new List(); /// /// 跳转画面 0:截点法 1:面积法 /// private int picture; /// /// 直径 /// public int diameter; /// /// 边距 /// public int margin; /// /// 长度(垂线) /// public int vLineLength; /// /// 长度(水平线) /// public int hLineLength; /// /// 左上到右下斜线长度 /// public int TopleftLineLength; /// /// 左下到右上斜线长度 /// public int ToprightLineLength; /// /// 垂线到圆距离 /// public int VLineToCDistance; /// /// 水平线到圆距离 /// public int HLineToCDistance; /// /// 线宽 /// public int lineWidth; /// % /// public decimal percentage; private Label label24; private NumericUpDown numericUpDown5; private Label label6; private NumericUpDown numericUpDown4; private Label label5; private NumericUpDown numericUpDown3; private Label label4; private NumericUpDown numericUpDown1; private Label label1; private DataGridViewTextBoxColumn GuideName; private int width; private int height; private ToolTip toolTip1; private IContainer components; /// /// 排列顺序 /// private int index = 0; public ArbitrationLawGuideDialog(int width, int height) { this.width = width; this.height = height; InitializeComponent(); InitializeLanguageText(); InitializeButtonBackgroudImage(); InitializeToolTip(); InitializeData(); //调色板 this.colorsForm = new ColorsForm(); this.colorsForm.StartPosition = FormStartPosition.CenterScreen; this.colorsForm.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged); } private void InitializeToolTip() { this.toolTip1 = new ToolTip(); this.toolTip1.SetToolTip(this.button3, PdnResources.GetString("Menu.Addto.text")); this.toolTip1.SetToolTip(this.button4, PdnResources.GetString("Menu.Edit.Text")); this.toolTip1.SetToolTip(this.button5, PdnResources.GetString("Menu.Edit.Delete.Text")); this.toolTip1.ShowAlways = true; } private void InitializeButtonBackgroudImage() { this.button3.FlatStyle = FlatStyle.Flat; this.button3.FlatAppearance.BorderSize = 0; this.button3.BackgroundImageLayout = ImageLayout.Center; this.button3.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListAddIcon.png").Reference; this.button4.FlatStyle = FlatStyle.Flat; this.button4.FlatAppearance.BorderSize = 0; this.button4.BackgroundImageLayout = ImageLayout.Center; this.button4.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListEditIcon.png").Reference; this.button5.FlatStyle = FlatStyle.Flat; this.button5.FlatAppearance.BorderSize = 0; this.button5.BackgroundImageLayout = ImageLayout.Center; this.button5.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListDeleteIcon.png").Reference; } private void RefreshGridIntersections() { float hGridSpacingDraw; float vGridSpacingDraw; if (PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Thefullgrid.text").Equals(this.comboBox1.SelectedItem)) { float space = 1; //避免不必要的提示网格尺寸已超出图像 if (this.numericUpDown5.Value > 0) space = (float)this.numericUpDown5.Value; hGridSpacingDraw = (float)(this.height - 2 * Convert.ToInt32(space)) / (Convert.ToInt32(this.numericUpDown1.Value) - 1); vGridSpacingDraw = (float)(this.width - 2 * Convert.ToInt32(space)) / ( Convert.ToInt32(this.numericUpDown3.Value) - 1); } else { hGridSpacingDraw = Convert.ToInt32(this.numericUpDown4.Value); vGridSpacingDraw = Convert.ToInt32(this.numericUpDown4.Value); } exceed = false; ArrayList xs = new ArrayList(); ArrayList ys = new ArrayList(); if ( Convert.ToInt32(this.numericUpDown1.Value) > 0) { if ( Convert.ToInt32(this.numericUpDown1.Value) % 2 == 0) { float Spacing = hGridSpacingDraw / 2; for (int i = 0; i < Convert.ToInt32(this.numericUpDown1.Value) / 2; i++) { if ((float)this.height / 2 - Spacing >= 0 && (float)this.height / 2 + Spacing <= this.height) { ys.Add((float)this.height / 2 - Spacing); ys.Add((float)this.height / 2 + Spacing); } else exceed = true; Spacing += hGridSpacingDraw; } } else { if ( Convert.ToInt32(this.numericUpDown1.Value) == 1) ys.Add((float)this.height / 2); else { float Spacing = hGridSpacingDraw; for (int i = 0; i < ( Convert.ToInt32(this.numericUpDown1.Value) - 1) / 2; i++) { if (i == 0) ys.Add((float)this.height / 2); if ((float)this.height / 2 - Spacing >= 0 && (float)this.height / 2 + Spacing <= this.height) { ys.Add((float)this.height / 2 - Spacing); ys.Add((float)this.height / 2 + Spacing); } else exceed = true; Spacing += hGridSpacingDraw; } } } } if ( Convert.ToInt32(this.numericUpDown3.Value) > 0) { if ( Convert.ToInt32(this.numericUpDown3.Value) % 2 == 0) { float Spacing = vGridSpacingDraw / 2; for (int i = 0; i < Convert.ToInt32(this.numericUpDown3.Value) / 2; i++) { if ((float)this.width / 2 - Spacing >= 0 && (float)this.width / 2 + Spacing <= this.width) { xs.Add((float)this.width / 2 - Spacing); xs.Add((float)this.width / 2 + Spacing); } else exceed = true; Spacing += vGridSpacingDraw; } } else { if ( Convert.ToInt32(this.numericUpDown3.Value) == 1) xs.Add((float)this.width / 2); else { float Spacing = vGridSpacingDraw; for (int i = 0; i < ( Convert.ToInt32(this.numericUpDown3.Value) - 1) / 2; i++) { if (i == 0) xs.Add((float)this.width / 2); if ((float)this.width / 2 + Spacing <= this.width && (float)this.width / 2 - Spacing >= 0) { xs.Add((float)this.width / 2 - Spacing); xs.Add((float)this.width / 2 + Spacing); } else exceed = true; Spacing += vGridSpacingDraw; } } } } if(exceed) MessageBox.Show(PdnResources.GetString("Menu.Thegridsizehasexceededtheimage.text")+"!"); } #region 初始化 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.Dedicatedanalysis.blackmetal.Gridmargin.text") + ":"; this.label5.Text = PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Gridspacing.text") + ":"; this.label4.Text = PdnResources.GetString("Menu.Numberofvertical.text") + ":"; this.label1.Text = PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Thelevelofthenumber.text") + ":"; this.label3.Text = PdnResources.GetString("Menu.Gridlinewidth.text") + ":"; this.comboBox1.Items.AddRange(new object[] { PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Thefullgrid.text"), PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Non-fullimagegrid.text")}); this.label7.Text = PdnResources.GetString("Menu.name.text") + ":"; this.label2.Text = PdnResources.GetString("Menu.Gridcolor.text") + ":"; this.label24.Text = PdnResources.GetString("Menu.Type.text") + ":"; this.groupBox3.Text = PdnResources.GetString("Menu.Preview.text"); this.groupBox4.Text = PdnResources.GetString("Menu.Preview.text"); this.Text = PdnResources.GetString("Menu.Auxiliarylinestylesettings.text"); } private void InitializeComponent() { this.components = new System.ComponentModel.Container(); 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.numericUpDown5 = new System.Windows.Forms.NumericUpDown(); this.numericUpDown4 = new System.Windows.Forms.NumericUpDown(); this.label6 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.numericUpDown3 = new System.Windows.Forms.NumericUpDown(); this.label4 = new System.Windows.Forms.Label(); this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); this.label1 = new System.Windows.Forms.Label(); this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); this.label3 = new System.Windows.Forms.Label(); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.textBox1 = new System.Windows.Forms.TextBox(); this.panel2 = new System.Windows.Forms.Panel(); this.label7 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label24 = new System.Windows.Forms.Label(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.panel1 = new System.Windows.Forms.Panel(); this.groupBox4 = new System.Windows.Forms.GroupBox(); this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.GuideName = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.button5 = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown5)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); this.groupBox3.SuspendLayout(); this.groupBox4.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.SuspendLayout(); // // groupBox1 // this.groupBox1.Controls.Add(this.button2); this.groupBox1.Controls.Add(this.button1); this.groupBox1.Location = new System.Drawing.Point(12, 12); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(500, 54); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; // // button2 // this.button2.Location = new System.Drawing.Point(414, 16); 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(325, 16); 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.numericUpDown5); this.groupBox2.Controls.Add(this.numericUpDown4); this.groupBox2.Controls.Add(this.label6); this.groupBox2.Controls.Add(this.label5); this.groupBox2.Controls.Add(this.numericUpDown3); this.groupBox2.Controls.Add(this.label4); this.groupBox2.Controls.Add(this.numericUpDown1); this.groupBox2.Controls.Add(this.label1); this.groupBox2.Controls.Add(this.numericUpDown2); this.groupBox2.Controls.Add(this.label3); this.groupBox2.Controls.Add(this.comboBox1); this.groupBox2.Controls.Add(this.textBox1); this.groupBox2.Controls.Add(this.panel2); this.groupBox2.Controls.Add(this.label7); this.groupBox2.Controls.Add(this.label2); this.groupBox2.Controls.Add(this.label24); this.groupBox2.Location = new System.Drawing.Point(193, 72); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(319, 177); this.groupBox2.TabIndex = 1; this.groupBox2.TabStop = false; // // numericUpDown5 // this.numericUpDown5.Location = new System.Drawing.Point(90, 116); this.numericUpDown5.Maximum = new decimal(new int[] { 10000, 0, 0, 0}); this.numericUpDown5.Name = "numericUpDown5"; this.numericUpDown5.Size = new System.Drawing.Size(67, 21); this.numericUpDown5.TabIndex = 37; this.numericUpDown5.Value = new decimal(new int[] { 1, 0, 0, 0}); this.numericUpDown5.ValueChanged += new System.EventHandler(this.numericUpDown5_ValueChanged); // // numericUpDown4 // this.numericUpDown4.Location = new System.Drawing.Point(90, 116); this.numericUpDown4.Maximum = new decimal(new int[] { 10000, 0, 0, 0}); this.numericUpDown4.Name = "numericUpDown4"; this.numericUpDown4.Size = new System.Drawing.Size(67, 21); this.numericUpDown4.TabIndex = 35; this.numericUpDown4.Value = new decimal(new int[] { 1, 0, 0, 0}); this.numericUpDown4.ValueChanged += new System.EventHandler(this.numericUpDown4_ValueChanged); // // label6 // this.label6.AutoSize = true; this.label6.Location = new System.Drawing.Point(19, 120); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(0, 12); this.label6.TabIndex = 36; // // label5 // this.label5.AutoSize = true; this.label5.Location = new System.Drawing.Point(19, 120); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(0, 12); this.label5.TabIndex = 34; // // numericUpDown3 // this.numericUpDown3.Location = new System.Drawing.Point(229, 85); this.numericUpDown3.Maximum = new decimal(new int[] { 10000, 0, 0, 0}); this.numericUpDown3.Name = "numericUpDown3"; this.numericUpDown3.Size = new System.Drawing.Size(67, 21); this.numericUpDown3.TabIndex = 33; this.numericUpDown3.Value = new decimal(new int[] { 1, 0, 0, 0}); this.numericUpDown3.ValueChanged += new System.EventHandler(this.numericUpDown3_ValueChanged); // // label4 // this.label4.AutoSize = true; this.label4.Location = new System.Drawing.Point(158, 88); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(0, 12); this.label4.TabIndex = 32; // // numericUpDown1 // this.numericUpDown1.Location = new System.Drawing.Point(90, 85); this.numericUpDown1.Maximum = new decimal(new int[] { 10000, 0, 0, 0}); this.numericUpDown1.Name = "numericUpDown1"; this.numericUpDown1.Size = new System.Drawing.Size(67, 21); this.numericUpDown1.TabIndex = 31; this.numericUpDown1.Value = new decimal(new int[] { 1, 0, 0, 0}); this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(19, 88); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(0, 12); this.label1.TabIndex = 30; // // numericUpDown2 // this.numericUpDown2.Location = new System.Drawing.Point(90, 146); this.numericUpDown2.Maximum = new decimal(new int[] { 10000, 0, 0, 0}); this.numericUpDown2.Name = "numericUpDown2"; this.numericUpDown2.Size = new System.Drawing.Size(67, 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); // // label3 // this.label3.AutoSize = true; this.label3.Location = new System.Drawing.Point(19, 150); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(0, 12); this.label3.TabIndex = 2; // // comboBox1 // this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBox1.FormattingEnabled = true; this.comboBox1.Location = new System.Drawing.Point(55, 49); this.comboBox1.Name = "comboBox1"; this.comboBox1.Size = new System.Drawing.Size(241, 20); this.comboBox1.TabIndex = 20; this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged_1); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(55, 17); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(241, 21); this.textBox1.TabIndex = 19; // // panel2 // this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.panel2.Location = new System.Drawing.Point(229, 116); this.panel2.Name = "panel2"; this.panel2.Size = new System.Drawing.Size(67, 21); this.panel2.TabIndex = 12; this.panel2.BackColorChanged += new System.EventHandler(this.panel2_BackColorChanged); this.panel2.Click += new System.EventHandler(this.panel2_Click); // // label7 // this.label7.AutoSize = true; this.label7.Location = new System.Drawing.Point(19, 23); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(0, 12); this.label7.TabIndex = 18; // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(160, 120); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(0, 12); this.label2.TabIndex = 1; // // label24 // this.label24.AutoSize = true; this.label24.Location = new System.Drawing.Point(19, 52); this.label24.Name = "label24"; this.label24.Size = new System.Drawing.Size(0, 12); this.label24.TabIndex = 29; // // groupBox3 // this.groupBox3.Controls.Add(this.panel1); this.groupBox3.Location = new System.Drawing.Point(193, 255); this.groupBox3.Name = "groupBox3"; this.groupBox3.Size = new System.Drawing.Size(319, 213); this.groupBox3.TabIndex = 1; this.groupBox3.TabStop = false; // // panel1 // this.panel1.Location = new System.Drawing.Point(6, 17); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(307, 190); this.panel1.TabIndex = 0; this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint); // // groupBox4 // this.groupBox4.Controls.Add(this.dataGridView1); this.groupBox4.Controls.Add(this.button5); this.groupBox4.Controls.Add(this.button4); this.groupBox4.Controls.Add(this.button3); this.groupBox4.Location = new System.Drawing.Point(12, 72); this.groupBox4.Name = "groupBox4"; this.groupBox4.Size = new System.Drawing.Size(175, 396); this.groupBox4.TabIndex = 2; this.groupBox4.TabStop = false; // // dataGridView1 // this.dataGridView1.AllowUserToAddRows = false; this.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.dataGridView1.BackgroundColor = System.Drawing.SystemColors.Control; this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView1.ColumnHeadersVisible = false; this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.GuideName}); this.dataGridView1.Location = new System.Drawing.Point(6, 53); this.dataGridView1.MultiSelect = false; this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.RowHeadersVisible = false; this.dataGridView1.RowTemplate.Height = 23; this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.dataGridView1.Size = new System.Drawing.Size(162, 337); this.dataGridView1.TabIndex = 4; this.dataGridView1.SelectionChanged += new System.EventHandler(this.dataGridView1_SelectionChanged); // // GuideName // this.GuideName.HeaderText = ""; this.GuideName.Name = "GuideName"; // // button5 // this.button5.Location = new System.Drawing.Point(138, 18); this.button5.Name = "button5"; this.button5.Size = new System.Drawing.Size(30, 25); this.button5.TabIndex = 3; this.button5.UseVisualStyleBackColor = true; this.button5.Click += new System.EventHandler(this.button5_Click); // // button4 // this.button4.Location = new System.Drawing.Point(104, 18); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(30, 25); this.button4.TabIndex = 2; this.button4.UseVisualStyleBackColor = true; this.button4.Click += new System.EventHandler(this.button4_Click); // // button3 // this.button3.Location = new System.Drawing.Point(70, 18); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(30, 25); this.button3.TabIndex = 1; this.button3.UseVisualStyleBackColor = true; this.button3.Click += new System.EventHandler(this.button3_Click); // // ArbitrationLawGuideDialog // this.ClientSize = new System.Drawing.Size(521, 473); this.Controls.Add(this.groupBox4); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.MaximizeBox = false; this.MaximumSize = new System.Drawing.Size(537, 512); this.MinimizeBox = false; this.MinimumSize = new System.Drawing.Size(537, 512); this.Name = "ArbitrationLawGuideDialog"; this.ShowInTaskbar = false; this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown5)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); this.groupBox3.ResumeLayout(false); this.groupBox4.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); this.ResumeLayout(false); } #endregion /// /// 初始化数据 /// private void InitializeData() { this.comboBox1.SelectedIndex = 0; this.groupBox2.Enabled = false; this.dataGridView1.ReadOnly = true; GrainSizeArbitrationLawModel grainSizeArbitrationLawModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeArbitrationLawModel.xml", FileMode.Open)); if (grainSizeArbitrationLawModel.GridStyleList != null) { foreach (var GridStyle in grainSizeArbitrationLawModel.GridStyleList) { index++; DataGridViewRow row = new DataGridViewRow(); foreach (DataGridViewColumn c in this.dataGridView1.Columns) { row.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell); } row.Cells[0].Value = GridStyle.gridName; this.dataGridView1.Rows.Add(row); ArrayList arrayList = new ArrayList(); arrayList.Add(GridStyle.gridName); arrayList.Add(GridStyle.hNumber); arrayList.Add(GridStyle.vNumber); arrayList.Add(GridStyle.gridWidth); arrayList.Add(GridStyle.gridSpacing); arrayList.Add(GridStyle.gridColor); arrayList.Add(GridStyle.wholePicture); arrayList.Add(GridStyle.blank); this.arrayLists.Add(arrayList); } } } /// /// 保存到配置文件 /// private void SaveXmlFile() { GrainSizeArbitrationLawModel grainSizeArbitrationLawModel = new GrainSizeArbitrationLawModel(); grainSizeArbitrationLawModel.GridStyleList = new List(); if(this.arrayLists.Count == 0) { //以下保存xml文件信息 string stageModelXml = XmlSerializeHelper.XmlSerialize(grainSizeArbitrationLawModel); string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeArbitrationLawModel.xml"; FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create); } foreach (ArrayList arrayList1 in this.arrayLists) { GrainSizeArbitrationLawModel.GridStyle gridStyle = new GrainSizeArbitrationLawModel.GridStyle(); gridStyle.gridName = arrayList1[0].ToString(); gridStyle.hNumber = Convert.ToInt32(arrayList1[1]); gridStyle.vNumber = Convert.ToInt32(arrayList1[2]); gridStyle.gridWidth = Convert.ToInt32(arrayList1[3]); gridStyle.gridSpacing = Convert.ToInt32(arrayList1[4]); gridStyle.gridColor = Convert.ToInt32(arrayList1[5]); gridStyle.wholePicture = Convert.ToBoolean(arrayList1[6]); gridStyle.blank = Convert.ToInt32(arrayList1[7]); grainSizeArbitrationLawModel.GridStyleList.Add(gridStyle); //以下保存xml文件信息 string stageModelXml = XmlSerializeHelper.XmlSerialize(grainSizeArbitrationLawModel); string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeArbitrationLawModel.xml"; FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create); } } /// /// 页面关闭 /// /// /// 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 InitGroupbox2() { this.textBox1.Clear(); this.comboBox1.SelectedIndex = 0; this.numericUpDown1.Value = 0; this.numericUpDown2.Value = 0; this.numericUpDown3.Value = 0; this.numericUpDown4.Value = 0; this.numericUpDown5.Value = 0; } /// /// 返回维护的辅助线 /// private void ReturnGrainSize() { ArrayList arrayList = new ArrayList(); for (int i = 0; i < this.dataGridView1.Rows.Count; i++) { arrayList.Add(this.dataGridView1.Rows[i].Cells[0].Value); } GrainSizeArbitrationLawDialog grainSizeArbitrationLawDialog = (GrainSizeArbitrationLawDialog)this.Owner; grainSizeArbitrationLawDialog.comboboxChange = false; grainSizeArbitrationLawDialog.InitComboboxValue(arrayList); } /// /// 保存按钮 /// /// /// private void button2_Click(object sender, EventArgs e) { // 添加 if (this.operation == 0) { if (string.IsNullOrEmpty(this.textBox1.Text)) { MessageBox.Show(PdnResources.GetString("Menu.namecannotbeEmpty.text")+"!"); } else { bool next = true; for (int r = 0; r < this.dataGridView1.Rows.Count; r++) { if (this.dataGridView1.Rows[r].Cells[0].Value.Equals(this.textBox1.Text)) { MessageBox.Show(PdnResources.GetString("Menu.Namealreadyexists.text")+"!"); next = false; break; } } if (next) { ArrayList arrayList = new ArrayList(); arrayList.Add(this.textBox1.Text); arrayList.Add(Convert.ToInt32(this.numericUpDown1.Value)); arrayList.Add(Convert.ToInt32(this.numericUpDown3.Value)); arrayList.Add(Convert.ToInt32(this.numericUpDown2.Value)); arrayList.Add(Convert.ToInt32(this.numericUpDown4.Value)); arrayList.Add(Convert.ToInt32(this.panel2.BackColor.ToArgb())); if (PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Thefullgrid.text").Equals(this.comboBox1.SelectedItem)) arrayList.Add(true); else if (PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Non-fullimagegrid.text").Equals(this.comboBox1.SelectedItem)) arrayList.Add(false); arrayList.Add(Convert.ToInt32(numericUpDown5.Value)); this.arrayLists.Add(arrayList); DataGridViewRow row = new DataGridViewRow(); foreach (DataGridViewColumn c in this.dataGridView1.Columns) { row.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell); } row.Cells[0].Value = this.textBox1.Text; this.dataGridView1.Rows.Add(row); SaveXmlFile(); MessageBox.Show(PdnResources.GetString("Menu.Addsuccessfully.text")+"!"); operation = -1; this.dataGridView1.Rows[this.dataGridView1.Rows.Count - 1].Selected = true; } } } // 编辑 else if (this.operation == 1) { if (string.IsNullOrEmpty(this.textBox1.Text)) { MessageBox.Show(PdnResources.GetString("Menu.namecannotbeEmpty.text")+"!"); } else { bool next = true; for (int r = 0; r < this.dataGridView1.Rows.Count; r++) { if (this.dataGridView1.Rows[r].Cells[0].Value.Equals(this.textBox1.Text) && this.dataGridView1.SelectedRows[0].Index != r) { MessageBox.Show(PdnResources.GetString("Menu.Namealreadyexists.text")+"!"); next = false; break; } } if (next) { int updIndex = 0; foreach (var arrayList1 in this.arrayLists) { if (arrayList1[0].ToString().Equals(this.dataGridView1.SelectedRows[0].Cells[0].Value)) { updIndex = Convert.ToInt32(arrayList1[arrayList1.Count - 1]); this.arrayLists.Remove(arrayList1); break; } } ArrayList arrayList = new ArrayList(); arrayList.Add(this.textBox1.Text); arrayList.Add(Convert.ToInt32(this.numericUpDown1.Value)); arrayList.Add(Convert.ToInt32(this.numericUpDown3.Value)); arrayList.Add(Convert.ToInt32(this.numericUpDown2.Value)); arrayList.Add(Convert.ToInt32(this.numericUpDown4.Value)); arrayList.Add(Convert.ToInt32(this.panel2.BackColor.ToArgb())); if (PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Thefullgrid.text").Equals(this.comboBox1.SelectedItem)) arrayList.Add(true); else if (PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Non-fullimagegrid.text").Equals(this.comboBox1.SelectedItem)) arrayList.Add(false); arrayList.Add(Convert.ToInt32(numericUpDown5.Value)); this.arrayLists.Add(arrayList); this.dataGridView1.SelectedRows[0].Cells[0].Value = this.textBox1.Text; SaveXmlFile(); MessageBox.Show(PdnResources.GetString("Menu.Editsuccessfully.text")+"!"); operation = -1; this.groupBox2.Enabled = false; } } } ReturnGrainSize(); } /// /// 辅助线样式预览 /// /// /// private void panel1_Paint(object sender, PaintEventArgs e) { Draw(e.Graphics); } /// /// 辅助线样式预览是(面积法) /// private void Draw(Graphics g) { Pen linePen = new Pen(this.panel2.BackColor,Convert.ToInt32(this.numericUpDown2.Value)); float hGridSpacingDraw; float vGridSpacingDraw; float blankDraw; bool wholePicture; int hNumber = Convert.ToInt32(this.numericUpDown1.Value) + 1; int vNumber = Convert.ToInt32(this.numericUpDown3.Value) + 1; float minX = this.panel1.Width / 2 - (vNumber - 1) * 10; float maxX = this.panel1.Width / 2 + (vNumber - 1) * 10; float minY = this.panel1.Height / 2 - (hNumber - 1) * 10; float maxY = this.panel1.Height / 2 + (hNumber - 1) * 10; if (PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Thefullgrid.text").Equals(this.comboBox1.SelectedItem)) wholePicture = true; else wholePicture = false; if (wholePicture) { hGridSpacingDraw = (float)this.panel1.Height / Convert.ToInt32(this.numericUpDown1.Value); vGridSpacingDraw = (float)this.panel1.Width / Convert.ToInt32(this.numericUpDown3.Value); blankDraw = 0; } else { blankDraw = 0; hGridSpacingDraw = 20; vGridSpacingDraw = 20; } if (hNumber > 0) { if (hNumber % 2 == 0) { float Spacing = hGridSpacingDraw / 2; for (int i = 0; i < (float)hNumber / 2; i++) { if (wholePicture) { if ((float)this.panel1.Height / 2 - Spacing >= blankDraw) { g.DrawLine(linePen, new PointF(blankDraw, (float)this.panel1.Height / 2 - Spacing) , new PointF((float)(this.panel1.Width - blankDraw), (float)this.panel1.Height / 2 - Spacing)); } if ((float)this.panel1.Height / 2 + Spacing <= this.panel1.Height - blankDraw) { g.DrawLine(linePen, new PointF(blankDraw, (float)this.panel1.Height / 2 + Spacing) , new PointF((float)(this.panel1.Width - blankDraw), (float)this.panel1.Height / 2 + Spacing)); } } else { if ((float)this.panel1.Height / 2 - Spacing >= 0) { g.DrawLine(linePen, new PointF(minX, (float)this.panel1.Height / 2 - Spacing) , new PointF(maxX, (float)this.panel1.Height / 2 - Spacing)); } if ((float)this.panel1.Height / 2 + Spacing <= this.panel1.Height) { g.DrawLine(linePen, new PointF(minX, (float)this.panel1.Height / 2 + Spacing) , new PointF(maxX, (float)this.panel1.Height / 2 + Spacing)); } } Spacing += hGridSpacingDraw; } } else { if ((float)this.panel1.Width > 2 * blankDraw) { if (hNumber == 1) g.DrawLine(linePen, new PointF(blankDraw, (float)this.panel1.Height / 2) , new PointF((float)(this.panel1.Width - blankDraw), (float)this.panel1.Height / 2)); else { float Spacing = hGridSpacingDraw; for (int i = 0; i < (hNumber - 1) / 2; i++) { if (wholePicture) { if (i == 0) g.DrawLine(linePen, new PointF(blankDraw, (float)this.panel1.Height / 2) , new PointF((float)(this.panel1.Width - blankDraw), (float)this.panel1.Height / 2)); if (this.panel1.Height / 2 - Spacing >= blankDraw) { g.DrawLine(linePen, new PointF(blankDraw, (float)this.panel1.Height / 2 - Spacing) , new PointF((float)(this.panel1.Width - blankDraw), (float)this.panel1.Height / 2 - Spacing)); } if (this.panel1.Height / 2 + Spacing <= this.panel1.Height - blankDraw) { g.DrawLine(linePen, new PointF(blankDraw, (float)this.panel1.Height / 2 + Spacing) , new PointF((float)(this.panel1.Width - blankDraw), (float)this.panel1.Height / 2 + Spacing)); } } else { if (i == 0) g.DrawLine(linePen, new PointF(minX, (float)this.panel1.Height / 2) , new PointF(maxX, (float)this.panel1.Height / 2)); if (this.panel1.Height / 2 - Spacing >= 0) { g.DrawLine(linePen, new PointF(minX, (float)this.panel1.Height / 2 - Spacing) , new PointF(maxX, (float)this.panel1.Height / 2 - Spacing)); } if (this.panel1.Height / 2 + Spacing <= this.panel1.Height) { g.DrawLine(linePen, new PointF(minX, (float)this.panel1.Height / 2 + Spacing) , new PointF(maxX, (float)this.panel1.Height / 2 + Spacing)); } } Spacing += hGridSpacingDraw; } } } } } if (vNumber > 0) { if (vNumber % 2 == 0) { float Spacing = vGridSpacingDraw / 2; for (int i = 0; i < (float)vNumber / 2; i++) { if (wholePicture) { if ((float)this.panel1.Width / 2 - Spacing >= 0 && (float)this.panel1.Width / 2 - Spacing >= blankDraw) { g.DrawLine(linePen, new PointF((float)this.panel1.Width / 2 - Spacing, blankDraw) , new PointF((float)this.panel1.Width / 2 - Spacing, (float)(this.panel1.Height - blankDraw))); } if ((float)this.panel1.Width / 2 + Spacing <= this.panel1.Width && (float)this.panel1.Width / 2 + Spacing <= this.panel1.Width - blankDraw) { g.DrawLine(linePen, new PointF((float)this.panel1.Width / 2 + Spacing, blankDraw) , new PointF((float)this.panel1.Width / 2 + Spacing, (float)(this.panel1.Height - blankDraw))); } } else { if ((float)this.panel1.Width / 2 - Spacing >= 0) { g.DrawLine(linePen, new PointF((float)this.panel1.Width / 2 - Spacing, minY) , new PointF((float)this.panel1.Width / 2 - Spacing, maxY)); } if ((float)this.panel1.Width / 2 + Spacing <= this.panel1.Width) { g.DrawLine(linePen, new PointF((float)this.panel1.Width / 2 + Spacing, minY) , new PointF((float)this.panel1.Width / 2 + Spacing, maxY)); } } Spacing += vGridSpacingDraw; } } else { if (this.panel1.Height > 2 * blankDraw) { if (vNumber == 1) g.DrawLine(linePen, new PointF((float)this.panel1.Width / 2, blankDraw) , new PointF((float)this.panel1.Width / 2, (float)(this.panel1.Height - blankDraw))); else { float Spacing = vGridSpacingDraw; for (int i = 0; i < (vNumber - 1) / 2; i++) { if (wholePicture) { if (i == 0) g.DrawLine(linePen, new PointF((float)this.panel1.Width / 2, blankDraw) , new PointF((float)this.panel1.Width / 2, (float)(this.panel1.Height - blankDraw))); if ((float)this.panel1.Width / 2 + Spacing <= this.panel1.Width && this.panel1.Width / 2 + Spacing <= this.panel1.Width - blankDraw) { g.DrawLine(linePen, new PointF((float)this.panel1.Width / 2 + Spacing, blankDraw) , new PointF((float)this.panel1.Width / 2 + Spacing, (float)(this.panel1.Height - blankDraw))); } if ((float)this.panel1.Width / 2 - Spacing >= 0 && (float)this.panel1.Width / 2 - Spacing >= blankDraw) { g.DrawLine(linePen, new PointF((float)this.panel1.Width / 2 - Spacing, blankDraw) , new PointF((float)this.panel1.Width / 2 - Spacing, (float)(this.panel1.Height - blankDraw))); } } else { if (i == 0) g.DrawLine(linePen, new PointF((float)this.panel1.Width / 2, minY) , new PointF((float)this.panel1.Width / 2, maxY)); if ((float)this.panel1.Width / 2 + Spacing <= this.panel1.Width) { g.DrawLine(linePen, new PointF((float)this.panel1.Width / 2 + Spacing, minY) , new PointF((float)this.panel1.Width / 2 + Spacing, maxY)); } if ((float)this.panel1.Width / 2 - Spacing >= 0) { g.DrawLine(linePen, new PointF((float)this.panel1.Width / 2 - Spacing, minY) , new PointF((float)this.panel1.Width / 2 - Spacing, maxY)); } } Spacing += vGridSpacingDraw; } } } } } } /// /// 线颜色改变 /// /// /// private void panel2_BackColorChanged(object sender, EventArgs e) { this.panel1.Refresh(); } /// /// 切换辅助线类型 /// /// /// private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e) { if (PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Thefullgrid.text").Equals(this.comboBox1.SelectedItem)) { this.label6.Visible = true; this.numericUpDown5.Visible = true; this.label5.Visible = false; this.numericUpDown4.Visible = false; } else if (PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Non-fullimagegrid.text").Equals(this.comboBox1.SelectedItem)) { this.label6.Visible = false; this.numericUpDown5.Visible = false; this.label5.Visible = true; this.numericUpDown4.Visible = true; } this.panel1.Refresh(); } /// /// 添加辅助线 /// /// /// private void button3_Click(object sender, EventArgs e) { // 添加 this.textBox1.Focus(); this.dataGridView1.ClearSelection(); operation = 0; this.groupBox2.Enabled = true; InitGroupbox2(); } /// /// 编辑辅助线 /// /// /// private void button4_Click(object sender, EventArgs e) { if(this.dataGridView1.Rows.Count > 0) { if(this.dataGridView1.SelectedRows.Count > 0) { // 编辑 operation = 1; this.groupBox2.Enabled = true; } else { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecttheauxiliarylinetoedit.text")+"!"); } } else { MessageBox.Show(PdnResources.GetString("Menu.Pleaseaddauxiliarylines.text")+"!"); } } /// /// 切换辅助线 /// /// /// private void dataGridView1_SelectionChanged(object sender, EventArgs e) { this.groupBox2.Enabled = false; if (this.dataGridView1.SelectedRows.Count > 0) { ArrayList arrayList1 = new ArrayList(); foreach (var arrayList in this.arrayLists) { if (this.dataGridView1.SelectedRows[0].Cells[0].Value.Equals(arrayList[0])) arrayList1 = arrayList; } this.textBox1.Text = arrayList1[0].ToString(); if (Convert.ToBoolean(arrayList1[6])) this.comboBox1.SelectedItem = PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Thefullgrid.text"); else this.comboBox1.SelectedItem = PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Non-fullimagegrid.text"); this.numericUpDown1.Value = Convert.ToInt32(arrayList1[1]); this.numericUpDown3.Value = Convert.ToInt32(arrayList1[2]); this.numericUpDown2.Value = Convert.ToInt32(arrayList1[3]); this.numericUpDown4.Value = Convert.ToInt32(arrayList1[4]); this.numericUpDown5.Value = Convert.ToInt32(arrayList1[7]); this.panel2.BackColor = Color.FromArgb(Convert.ToInt32(arrayList1[5])); this.panel1.Refresh(); } } /// /// 删除辅助线 /// /// /// private void button5_Click(object sender, EventArgs e) { if(this.dataGridView1.SelectedRows.Count > 0) { DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretodeletetheauxiliaryline?.text")+"?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { foreach (var arrayList in this.arrayLists) { if (this.dataGridView1.SelectedRows[0].Cells[0].Value.Equals(arrayList[0])) { this.arrayLists.Remove(arrayList); break; } } SaveXmlFile(); this.dataGridView1.Rows.Remove(this.dataGridView1.SelectedRows[0]); if (this.dataGridView1.Rows.Count == 0) InitGroupbox2(); ReturnGrainSize(); } this.panel1.Refresh(); } else { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecttheauxiliarylinetodelete.text")+"!"); } } /// /// 间距 /// /// /// private void numericUpDown21_ValueChanged(object sender, EventArgs e) { this.panel1.Refresh(); } /// /// 线条数 /// /// /// private void numericUpDown20_ValueChanged(object sender, EventArgs e) { this.panel1.Refresh(); } /// /// 间距 /// /// /// private void numericUpDown17_ValueChanged(object sender, EventArgs e) { this.panel1.Refresh(); } /// /// 线条数 /// /// /// private void numericUpDown19_ValueChanged(object sender, EventArgs e) { this.panel1.Refresh(); } int hOldValue; int vOldValue; int sOldValue; int bOldValue; private void numericUpDown1_ValueChanged(object sender, EventArgs e) { RefreshGridIntersections(); if (this.exceed) this.numericUpDown1.Value = this.hOldValue; this.hOldValue = Convert.ToInt32(this.numericUpDown1.Value); this.panel1.Refresh(); } private void numericUpDown3_ValueChanged(object sender, EventArgs e) { RefreshGridIntersections(); if (this.exceed) this.numericUpDown3.Value = this.vOldValue; this.vOldValue = Convert.ToInt32(this.numericUpDown3.Value); this.panel1.Refresh(); } private void numericUpDown5_ValueChanged(object sender, EventArgs e) { RefreshGridIntersections(); if (this.exceed) this.numericUpDown5.Value = this.bOldValue; this.bOldValue = Convert.ToInt32(this.numericUpDown5.Value); this.panel1.Refresh(); } private void numericUpDown4_ValueChanged(object sender, EventArgs e) { RefreshGridIntersections(); if (this.exceed) this.numericUpDown4.Value = this.sOldValue; this.sOldValue = Convert.ToInt32(this.numericUpDown4.Value); this.panel1.Refresh(); } private void numericUpDown2_ValueChanged(object sender, EventArgs e) { this.panel1.Refresh(); } } }