using PaintDotNet.Adjust; using PaintDotNet.Base.CommTool; using PaintDotNet.Processing.DepthExtensionComponent; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace PaintDotNet.Processing { /// /// 图像拼接 /// internal class ImageMosaicsDialog : PdnBaseForm { private Button button1; private Button button3; private Button button2; private Button button4; private Button button5; private GroupBox groupBox2; private Label label1; private TextBox tbxColunmN; private Label label2; private TextBox textBox2; private GroupBox groupBox3; private Panel panel1; private GroupBox groupBox1; private GroupBox groupBoxStep2Operate; private Button btnFromFile; private Button btnFromApp; private GroupBox groupBox5; private Panel panel2; private GroupBox groupBox6; private GroupBox groupBox7; private Button button8; private TextBox textBox3; private Label label3; private PictureBox pictureBox1; private AppWorkspace appWorkspace; /// /// 是否重置picturebox中的矩形尺寸 /// private bool _isFirst = true; /// /// 是否为拖动picturebox中的矩形框 /// private bool isMoved = false; /// /// 是否为修改picturebox中的矩形框大小 /// private bool isResized = false; /// /// 辅助计算偏移量 /// private Point _lastPoint = new Point(0, 0); /// /// picturebox中图片对应矩形 /// private Rectangle imageRect; /// /// picturebox中选择框对应矩形 /// private Rectangle zoomRect; /// /// 命名 /// private string stepNumber = "001"; /// /// 图片选择窗口 /// private InterImagePickerDialog imagePickerDialog; /// /// 拼接后的图片 /// private Bitmap _mosaicsImage; /// /// 图片自定义控件判断鼠标是否按下 /// private bool isMouseDown = false; /// /// 自定义控件的location /// private Point picToolLocation; /// /// 鼠标的按下位置 /// private Point mouseOffset; /// /// 控件拖动前的location /// private Point oldToolLocation; private Label label4; private NumericUpDown numOverlapRate; /// /// 控件拖动前的tag值 /// private int oldToolTag; public ImageMosaicsDialog(AppWorkspace appWorkspace) { this.appWorkspace = appWorkspace; InitializeComponent(); InitializeLanguageText(); InitializeOtherInfo(); AddPitureboxTools(); ReloadStepTwoControls(); } private void InitializeLanguageText() { this.button3.Text = PdnResources.GetString("Menu.thirdstep.text"); this.button4.Text = PdnResources.GetString("Menu.Nextstep.text"); this.button5.Text = PdnResources.GetString("Menu.return.text"); this.groupBox1.Text = PdnResources.GetString("Menu.operation.text"); this.button2.Text = PdnResources.GetString("Menu.Secondstep.text"); this.button1.Text = PdnResources.GetString("Menu.firststep.text"); this.groupBox2.Text = PdnResources.GetString("Menu.Setting.Text"); this.label2.Text = PdnResources.GetString("Menu.ImageProcessing.Imagestitching.Thenumberofvertical.text") + ":"; this.label1.Text = PdnResources.GetString("Menu.ImageProcessing.Imagestitching.Thelevelofthenumber.text") + ":"; this.groupBox3.Text = PdnResources.GetString("Menu.Preview.text"); this.groupBoxStep2Operate.Text = PdnResources.GetString("Menu.Selectpicturefrom.text"); this.btnFromFile.Text = PdnResources.GetString("Menu.Harddiskfile.text"); this.btnFromApp.Text = PdnResources.GetString("Menu.Currentsoftware.text"); this.groupBox5.Text = PdnResources.GetString("Menu.Preview.text"); this.groupBox6.Text = PdnResources.GetString("Menu.finish.text"); this.button8.Text = PdnResources.GetString("Menu.File.Save.Text"); this.label3.Text = PdnResources.GetString("Menu.Imagename.text") + ":"; this.groupBox7.Text = PdnResources.GetString("Menu.Preview.text"); this.Text = PdnResources.GetString("Menu.ImageCollection.ImageStitching.Text"); } /// /// 初始化基础控件 /// private void InitializeComponent() { this.groupBox1 = new System.Windows.Forms.GroupBox(); this.button5 = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.textBox2 = new System.Windows.Forms.TextBox(); this.tbxColunmN = new System.Windows.Forms.TextBox(); 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.groupBoxStep2Operate = new System.Windows.Forms.GroupBox(); this.numOverlapRate = new System.Windows.Forms.NumericUpDown(); this.label4 = new System.Windows.Forms.Label(); this.btnFromFile = new System.Windows.Forms.Button(); this.btnFromApp = new System.Windows.Forms.Button(); this.groupBox5 = new System.Windows.Forms.GroupBox(); this.panel2 = new System.Windows.Forms.Panel(); this.groupBox6 = new System.Windows.Forms.GroupBox(); this.button8 = new System.Windows.Forms.Button(); this.textBox3 = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.groupBox7 = new System.Windows.Forms.GroupBox(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); this.groupBoxStep2Operate.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numOverlapRate)).BeginInit(); this.groupBox5.SuspendLayout(); this.groupBox6.SuspendLayout(); this.groupBox7.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.SuspendLayout(); // // groupBox1 // this.groupBox1.Controls.Add(this.button5); this.groupBox1.Controls.Add(this.button4); this.groupBox1.Controls.Add(this.button3); this.groupBox1.Controls.Add(this.button2); this.groupBox1.Controls.Add(this.button1); this.groupBox1.Location = new System.Drawing.Point(13, 13); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(88, 603); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; this.groupBox1.Text = "操作"; // // button5 // this.button5.Location = new System.Drawing.Point(6, 480); this.button5.Name = "button5"; this.button5.Size = new System.Drawing.Size(75, 23); this.button5.TabIndex = 4; this.button5.Text = "返回"; this.button5.UseVisualStyleBackColor = true; this.button5.Click += new System.EventHandler(this.button5_Click); // // button4 // this.button4.Location = new System.Drawing.Point(6, 517); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(75, 23); this.button4.TabIndex = 3; this.button4.Text = "下一步"; this.button4.UseVisualStyleBackColor = true; this.button4.Click += new System.EventHandler(this.button4_Click); // // button3 // this.button3.Location = new System.Drawing.Point(7, 124); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(75, 23); this.button3.TabIndex = 2; this.button3.Text = "第三步"; this.button3.UseVisualStyleBackColor = true; this.button3.Click += new System.EventHandler(this.button3_Click); // // button2 // this.button2.Location = new System.Drawing.Point(7, 86); 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); // // button1 // this.button1.Location = new System.Drawing.Point(7, 48); 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); // // groupBox2 // this.groupBox2.Controls.Add(this.textBox2); this.groupBox2.Controls.Add(this.tbxColunmN); this.groupBox2.Controls.Add(this.label2); this.groupBox2.Controls.Add(this.label1); this.groupBox2.Location = new System.Drawing.Point(123, 13); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(623, 60); this.groupBox2.TabIndex = 1; this.groupBox2.TabStop = false; // // textBox2 // this.textBox2.Location = new System.Drawing.Point(418, 22); this.textBox2.Name = "textBox2"; this.textBox2.Size = new System.Drawing.Size(140, 21); this.textBox2.TabIndex = 3; this.textBox2.Text = "4"; this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged); this.textBox2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox2_KeyPress); // // tbxColunmN // this.tbxColunmN.Location = new System.Drawing.Point(117, 22); this.tbxColunmN.Name = "tbxColunmN"; this.tbxColunmN.Size = new System.Drawing.Size(140, 21); this.tbxColunmN.TabIndex = 2; this.tbxColunmN.Text = "3"; this.tbxColunmN.TextChanged += new System.EventHandler(this.textBox1_TextChanged); this.tbxColunmN.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress); // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(356, 26); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(0, 12); this.label2.TabIndex = 1; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(55, 26); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(0, 12); this.label1.TabIndex = 0; // // groupBox3 // this.groupBox3.Controls.Add(this.panel1); this.groupBox3.Location = new System.Drawing.Point(123, 89); this.groupBox3.Name = "groupBox3"; this.groupBox3.Size = new System.Drawing.Size(623, 527); this.groupBox3.TabIndex = 2; this.groupBox3.TabStop = false; // // panel1 // this.panel1.AutoScroll = true; this.panel1.BackColor = System.Drawing.Color.Transparent; this.panel1.Location = new System.Drawing.Point(6, 14); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(611, 507); this.panel1.TabIndex = 0; // // groupBoxStep2Operate // this.groupBoxStep2Operate.Controls.Add(this.numOverlapRate); this.groupBoxStep2Operate.Controls.Add(this.label4); this.groupBoxStep2Operate.Controls.Add(this.btnFromFile); this.groupBoxStep2Operate.Controls.Add(this.btnFromApp); this.groupBoxStep2Operate.Location = new System.Drawing.Point(123, 13); this.groupBoxStep2Operate.Name = "groupBoxStep2Operate"; this.groupBoxStep2Operate.Size = new System.Drawing.Size(623, 60); this.groupBoxStep2Operate.TabIndex = 3; this.groupBoxStep2Operate.TabStop = false; // // numOverlapRate // this.numOverlapRate.DecimalPlaces = 2; this.numOverlapRate.Increment = new decimal(new int[] { 5, 0, 0, 131072}); this.numOverlapRate.Location = new System.Drawing.Point(99, 23); this.numOverlapRate.Maximum = new decimal(new int[] { 1, 0, 0, 0}); this.numOverlapRate.Minimum = new decimal(new int[] { 5, 0, 0, 131072}); this.numOverlapRate.Name = "numOverlapRate"; this.numOverlapRate.Size = new System.Drawing.Size(60, 21); this.numOverlapRate.TabIndex = 4; this.numOverlapRate.Value = new decimal(new int[] { 10, 0, 0, 131072}); // // label4 // this.label4.AutoSize = true; this.label4.Location = new System.Drawing.Point(16, 26); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(77, 12); this.label4.TabIndex = 3; this.label4.Text = "Overlap rate"; // // btnFromFile // this.btnFromFile.Location = new System.Drawing.Point(526, 20); this.btnFromFile.Name = "btnFromFile"; this.btnFromFile.Size = new System.Drawing.Size(75, 23); this.btnFromFile.TabIndex = 1; this.btnFromFile.UseVisualStyleBackColor = true; this.btnFromFile.Click += new System.EventHandler(this.button7_Click); // // btnFromApp // this.btnFromApp.Location = new System.Drawing.Point(414, 20); this.btnFromApp.Name = "btnFromApp"; this.btnFromApp.Size = new System.Drawing.Size(75, 23); this.btnFromApp.TabIndex = 0; this.btnFromApp.UseVisualStyleBackColor = true; this.btnFromApp.Click += new System.EventHandler(this.button6_Click); // // groupBox5 // this.groupBox5.Controls.Add(this.panel2); this.groupBox5.Location = new System.Drawing.Point(123, 89); this.groupBox5.Name = "groupBox5"; this.groupBox5.Size = new System.Drawing.Size(623, 527); this.groupBox5.TabIndex = 4; this.groupBox5.TabStop = false; // // panel2 // this.panel2.AutoScroll = true; this.panel2.Location = new System.Drawing.Point(6, 14); this.panel2.Name = "panel2"; this.panel2.Size = new System.Drawing.Size(611, 507); this.panel2.TabIndex = 0; // // groupBox6 // this.groupBox6.Controls.Add(this.button8); this.groupBox6.Controls.Add(this.textBox3); this.groupBox6.Controls.Add(this.label3); this.groupBox6.Location = new System.Drawing.Point(123, 13); this.groupBox6.Name = "groupBox6"; this.groupBox6.Size = new System.Drawing.Size(623, 60); this.groupBox6.TabIndex = 5; this.groupBox6.TabStop = false; this.groupBox6.Text = "设置"; // // button8 // this.button8.Location = new System.Drawing.Point(511, 20); this.button8.Name = "button8"; this.button8.Size = new System.Drawing.Size(75, 23); this.button8.TabIndex = 2; this.button8.Text = "保存"; this.button8.UseVisualStyleBackColor = true; this.button8.Click += new System.EventHandler(this.button8_Click); // // textBox3 // this.textBox3.Location = new System.Drawing.Point(93, 22); this.textBox3.Name = "textBox3"; this.textBox3.Size = new System.Drawing.Size(167, 21); this.textBox3.TabIndex = 1; // // label3 // this.label3.AutoSize = true; this.label3.Location = new System.Drawing.Point(28, 25); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(65, 12); this.label3.TabIndex = 0; this.label3.Text = "图像名称:"; // // groupBox7 // this.groupBox7.Controls.Add(this.pictureBox1); this.groupBox7.Location = new System.Drawing.Point(123, 89); this.groupBox7.Name = "groupBox7"; this.groupBox7.Size = new System.Drawing.Size(623, 527); this.groupBox7.TabIndex = 6; this.groupBox7.TabStop = false; this.groupBox7.Text = "预览"; // // pictureBox1 // this.pictureBox1.Location = new System.Drawing.Point(6, 14); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(611, 507); this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; // // ImageMosaicsDialog // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.ClientSize = new System.Drawing.Size(758, 628); this.Controls.Add(this.groupBox7); this.Controls.Add(this.groupBox5); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.Controls.Add(this.groupBox6); this.Controls.Add(this.groupBoxStep2Operate); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "ImageMosaicsDialog"; this.Text = "图像拼接"; this.Controls.SetChildIndex(this.groupBoxStep2Operate, 0); this.Controls.SetChildIndex(this.groupBox6, 0); this.Controls.SetChildIndex(this.groupBox1, 0); this.Controls.SetChildIndex(this.groupBox2, 0); this.Controls.SetChildIndex(this.groupBox3, 0); this.Controls.SetChildIndex(this.groupBox5, 0); this.Controls.SetChildIndex(this.groupBox7, 0); this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); this.groupBox3.ResumeLayout(false); this.groupBoxStep2Operate.ResumeLayout(false); this.groupBoxStep2Operate.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.numOverlapRate)).EndInit(); this.groupBox5.ResumeLayout(false); this.groupBox6.ResumeLayout(false); this.groupBox6.PerformLayout(); this.groupBox7.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false); } /// /// 初始化其他控件 /// private void InitializeOtherInfo() { //第一次进入页面的"第一步"按钮样式 this.button1.BackColor = Color.Gray; this.button1.ForeColor = Color.White; this.button1.FlatStyle = FlatStyle.Flat; this.button1.FlatAppearance.BorderSize = 0; this.groupBoxStep2Operate.Visible = false; this.groupBox5.Visible = false; this.groupBox6.Visible = false; this.groupBox7.Visible = false; this.pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint); this.pictureBox1.MouseDown += new MouseEventHandler(pictureBox1_MouseDown); this.pictureBox1.MouseMove += new MouseEventHandler(pictureBox1_MouseMove); } /// /// 加载空白图片控件 /// private void AddPitureboxTools() { int colNum = this.tbxColunmN.Text == "" ? 0 : Convert.ToInt32(this.tbxColunmN.Text);//列数 if (colNum == 0) { MessageBox.Show(PdnResources.GetString("Menu.henumberoflevelsisnotcorrecpleasereset.Text")); return; } int rowNum = this.textBox2.Text == "" ? 0 : Convert.ToInt32(this.textBox2.Text);//行数 if (rowNum == 0) { MessageBox.Show(PdnResources.GetString("Menu.Theverticanumberisnotcorrectpleasereset.Text")); return; } Point startPoint = new Point(0, 4); if (colNum < 5) startPoint.X = (this.panel1.Width - (116 * colNum)) / (colNum + 1); int marginTB = 7;//固定的上下边距 //滚动条不用处理,直接刷整个控件? for (int i = 0; i < colNum; i++) { for (int j = 0; j < rowNum; j++) { PictureBox pictureBox = new PictureBox(); pictureBox.Size = new Size(116, 116); if (colNum >= 5) { pictureBox.Location = new Point((120 * i), startPoint.Y + ((116 + marginTB) * j)); } else//水平数小于5时,边距是动态的 pictureBox.Location = new Point(startPoint.X + ((startPoint.X + 116) * i), startPoint.Y + ((116 + marginTB) * j)); pictureBox.BackColor = Color.White; this.panel1.Controls.Add(pictureBox); } } } /// /// 修改水平个数刷新panel /// /// /// private void textBox1_TextChanged(object sender, EventArgs e) { if (tbxColunmN.Text.Trim() == "" || textBox2.Text.Trim() == "") { return; } //tbxColunmN.Invoke(new EventHandler(delegate { // tbxColunmN.Text = int.Parse(tbxColunmN.Text) * int.Parse(textBox2.Text) > 1000 ? (int)(1000 / int.Parse(textBox2.Text)) + "" : tbxColunmN.Text; //})); if (int.Parse(textBox2.Text) * int.Parse(tbxColunmN.Text) > 1000) { tbxColunmN.Text = (int)(1000 / int.Parse(textBox2.Text)) + ""; return; } this.panel1.Controls.Clear(); AddPitureboxTools(); ReloadStepTwoControls(); FocusToCaret(tbxColunmN); } /// /// 修改垂直个数刷新panel /// /// /// private void textBox2_TextChanged(object sender, EventArgs e) { if (tbxColunmN.Text.Trim() == "" || textBox2.Text.Trim() == "") { return; } //textBox2.Invoke(new EventHandler(delegate { // textBox2.Text = int.Parse(textBox2.Text) * int.Parse(tbxColunmN.Text) > 1000 ? (int)(1000 / int.Parse(tbxColunmN.Text)) + "" : textBox2.Text; //})); if (int.Parse(textBox2.Text) * int.Parse(tbxColunmN.Text) > 1000) { textBox2.Text = (int)(1000 / int.Parse(tbxColunmN.Text)) + ""; return; } this.panel1.Controls.Clear(); AddPitureboxTools(); ReloadStepTwoControls(); FocusToCaret(textBox2); } /// /// 限制只可以输入0-9数字以及退格键 /// /// /// private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar != '\b')//这是允许输入退格键              { int len = this.tbxColunmN.Text.Length; if (len < 1 && e.KeyChar == '0') { e.Handled = true; } else if ((e.KeyChar < '0') || (e.KeyChar > '9'))//这是允许输入0-9数字                  { e.Handled = true; } } } /// /// 限制只可以输入0-9数字以及退格键 /// /// /// private void textBox2_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar != '\b')//这是允许输入退格键              { int len = this.textBox2.Text.Length; if (len < 1 && e.KeyChar == '0') { e.Handled = true; } else if ((e.KeyChar < '0') || (e.KeyChar > '9'))//这是允许输入0-9数字                  { e.Handled = true; } } } void FocusToCaret(TextBox txt) { txt.Focus(); txt.Select(this.tbxColunmN.TextLength, 0); txt.ScrollToCaret(); } /// /// 点击当前软件按钮 /// /// /// private void button6_Click(object sender, EventArgs e) { if (imagePickerDialog == null) { imagePickerDialog = new InterImagePickerDialog(this.appWorkspace); imagePickerDialog.StartPosition = FormStartPosition.Manual; imagePickerDialog.Left = ((Button)sender).Left + 12 + this.Left; imagePickerDialog.Top = ((Button)sender).Bottom + 36 + this.Top; imagePickerDialog.ValueChanged += new System.EventHandler(this.inputMat_ValueChanged); imagePickerDialog.Show(); } else { if (!imagePickerDialog.IsDisposed) { imagePickerDialog.WindowState = FormWindowState.Normal; } else { imagePickerDialog = new InterImagePickerDialog(this.appWorkspace); imagePickerDialog.StartPosition = FormStartPosition.Manual; imagePickerDialog.Left = ((Button)sender).Left + 12 + this.Left; imagePickerDialog.Top = ((Button)sender).Bottom + 36 + this.Top; imagePickerDialog.ValueChanged += new System.EventHandler(this.inputMat_ValueChanged); imagePickerDialog.Show(); } } } /// /// 从图库选择待对照图片 /// /// /// private void inputMat_ValueChanged(object sender, EventArgs e) { if (sender is DocumentWorkspace) { Bitmap bitmap = ((DocumentWorkspace)sender).CompositionSurface.CreateAliasedBitmap(); foreach (Control C in this.panel2.Controls) { if (C is DepthExtensionPicTool) { DepthExtensionPicTool depthExtensionPicTool = (DepthExtensionPicTool)C; if (depthExtensionPicTool.pictureBox1.Image == null) { if (bitmap.Width > depthExtensionPicTool.pictureBox1.Size.Width || bitmap.Height > depthExtensionPicTool.pictureBox1.Size.Height) { depthExtensionPicTool.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; } else { depthExtensionPicTool.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage; } depthExtensionPicTool.pictureBox1.Image = bitmap; depthExtensionPicTool.panel2.Visible = false; depthExtensionPicTool.panel1.Visible = true; //根据插入的控件位置修改滚动条 Point oldScrollPoint = this.panel2.AutoScrollPosition; Point scrollPoint = new Point(depthExtensionPicTool.Location.X + Math.Abs(oldScrollPoint.X) + depthExtensionPicTool.Width - this.panel2.Width, depthExtensionPicTool.Location.Y + Math.Abs(oldScrollPoint.Y) + depthExtensionPicTool.Height - this.panel2.Height); if (this.panel2.HorizontalScroll.Visible) scrollPoint.X += 16;//固定滚动条尺寸,可能不是完全精准 if (this.panel2.VerticalScroll.Visible) scrollPoint.Y += 16;//固定滚动条尺寸,可能不是完全精准 this.panel2.AutoScrollPosition = scrollPoint; return; } } } } } /// /// 点击硬盘文件按钮 /// /// /// private void button7_Click(object sender, EventArgs e) { List listBitmap = ChooseImagesFromHardDisk(); if (listBitmap != null && listBitmap.Count > 0) { int addedImgNum = 0; for (int i = 0; i < listBitmap.Count; i++) { foreach (Control C in this.panel2.Controls) { if (C is DepthExtensionPicTool) { DepthExtensionPicTool depthExtensionPicTool = (DepthExtensionPicTool)C; if (depthExtensionPicTool.pictureBox1.Image == null) { if (listBitmap[i].Width > depthExtensionPicTool.pictureBox1.Size.Width || listBitmap[i].Height > depthExtensionPicTool.pictureBox1.Size.Height) { depthExtensionPicTool.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; } else { depthExtensionPicTool.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage; } depthExtensionPicTool.pictureBox1.Image = listBitmap[i]; depthExtensionPicTool.panel2.Visible = false; depthExtensionPicTool.panel1.Visible = true; addedImgNum++; //如果添加的是最后一张图,移动panel的滚动条到该控件位置 if (addedImgNum == listBitmap.Count) { //根据插入的控件位置修改滚动条 Point oldScrollPoint = this.panel2.AutoScrollPosition; Point scrollPoint = new Point(depthExtensionPicTool.Location.X + Math.Abs(oldScrollPoint.X) + depthExtensionPicTool.Width - this.panel2.Width, depthExtensionPicTool.Location.Y + Math.Abs(oldScrollPoint.Y) + depthExtensionPicTool.Height - this.panel2.Height); if (this.panel2.HorizontalScroll.Visible) scrollPoint.X += 16; if (this.panel2.VerticalScroll.Visible) scrollPoint.Y += 16; this.panel2.AutoScrollPosition = scrollPoint; } break; } } } } } } /// /// 从硬盘选择单张图片 /// /// private Bitmap ChooseImageFromHardDisk() { var openFileDialog = new OpenFileDialog { Filter = "*.jpg,*jpeg,*.bmp,*.ico,*.png,*.tif,*.wmf|*.jpg;*jpeg;*.bmp;*.ico;*.png;*.tif;*.wmf" }; if (openFileDialog.ShowDialog() == DialogResult.OK) { Image image = Image.FromFile(openFileDialog.FileName); Bitmap newBit = new Bitmap(image); return newBit; } else { return null; } } /// /// 从硬盘选择多张图片 /// /// private List ChooseImagesFromHardDisk() { var openFileDialog = new OpenFileDialog { Filter = "*.jpg,*jpeg,*.bmp,*.ico,*.png,*.tif,*.wmf|*.jpg;*jpeg;*.bmp;*.ico;*.png;*.tif;*.wmf" }; openFileDialog.Multiselect = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { string[] imageNames = openFileDialog.FileNames; List listBitmap = new List(); foreach (string imgName in imageNames) { Image image = Image.FromFile(imgName); listBitmap.Add(new Bitmap(image)); } return listBitmap; } else { return null; } } /// /// 第一步按钮 /// /// /// private void button1_Click(object sender, EventArgs e) { if (this.groupBox2.Visible && this.groupBox3.Visible) return; ChangeButtonStyle(this.button1, this.button2, this.button3); this.groupBoxStep2Operate.Visible = false; this.groupBox5.Visible = false; this.groupBox6.Visible = false; this.groupBox7.Visible = false; this.groupBox2.Visible = true; this.groupBox3.Visible = true; } /// /// 第二步按钮 /// /// /// private void button2_Click(object sender, EventArgs e) { if (this.groupBoxStep2Operate.Visible && this.groupBox5.Visible) return; ChangeButtonStyle(this.button2, this.button1, this.button3); this.groupBox2.Visible = false; this.groupBox3.Visible = false; this.groupBox6.Visible = false; this.groupBox7.Visible = false; this.groupBoxStep2Operate.Visible = true; this.groupBox5.Visible = true; } /// /// 初始化第二步的图片自定义控件 /// private void ReloadStepTwoControls() { this.panel2.Controls.Clear(); if (!string.IsNullOrEmpty(this.tbxColunmN.Text) && !string.IsNullOrEmpty(this.textBox2.Text)) { int colNum = this.tbxColunmN.Text == "" ? 0 : Convert.ToInt32(this.tbxColunmN.Text);//列数 int rowNum = this.textBox2.Text == "" ? 0 : Convert.ToInt32(this.textBox2.Text);//行数 int toolsTagNum = 1; Point startPoint = new Point(0, 4); if (colNum < 5) startPoint.X = (this.panel1.Width - (116 * colNum)) / (colNum + 1); int marginTB = 7;//固定的上下边距 for (int i = 0; i < rowNum; i++) { for (int j = 0; j < colNum; j++) { DepthExtensionPicTool depthExtensionPicTool = new DepthExtensionPicTool(); depthExtensionPicTool.Tag = toolsTagNum; depthExtensionPicTool.Size = new Size(116, 116); if (colNum >= 5) depthExtensionPicTool.Location = new Point((120 * j), startPoint.Y + ((116 + marginTB) * i)); else//水平数小于5时,边距是动态的 depthExtensionPicTool.Location = new Point(startPoint.X + ((startPoint.X + 116) * j), startPoint.Y + ((116 + marginTB) * i)); depthExtensionPicTool.panel1.Cursor = Cursors.Hand; depthExtensionPicTool.panel1.Paint += new PaintEventHandler(panelDel_Paint); depthExtensionPicTool.panel1.Click += new EventHandler(panelDel_Click); depthExtensionPicTool.panel2.Cursor = Cursors.Hand; depthExtensionPicTool.panel2.Paint += new PaintEventHandler(panelAdd_Paint); depthExtensionPicTool.panel2.Click += new EventHandler(panelAdd_Click); depthExtensionPicTool.pictureBox1.MouseDown += new MouseEventHandler(picTool_MouseDown); depthExtensionPicTool.pictureBox1.MouseMove += new MouseEventHandler(picTool_MouseMove); depthExtensionPicTool.pictureBox1.MouseUp += new MouseEventHandler(picTool_MouseUp); this.panel2.Controls.Add(depthExtensionPicTool); toolsTagNum++; if (colNum > 1)//只有一列不绘制"倒置"button { if (j == colNum - 1) { Button convertButton = new Button(); convertButton.Name = "convertButton"; convertButton.Text = PdnResources.GetString("Menu.ImageProcessing.Imagestitching.upside-down.text"); convertButton.Tag = i + 1; convertButton.Size = new System.Drawing.Size(50, 23); if (colNum >= 5) convertButton.Location = new Point((120 * j) + 116 + 10, startPoint.Y + ((116 + marginTB) * i) + 47); else convertButton.Location = new Point(startPoint.X + ((startPoint.X + 116) * j) + 116 + 15, startPoint.Y + ((116 + marginTB) * i) + 47); convertButton.Click += new EventHandler(convertButton_Click); this.panel2.Controls.Add(convertButton); } } } } } } /// /// 图片自定义控件的鼠标按下事件 /// /// /// private void picTool_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { isMouseDown = true; PictureBox pictureBox = (PictureBox)sender; ((DepthExtensionPicTool)pictureBox.Parent).Cursor = Cursors.SizeAll; picToolLocation = ((DepthExtensionPicTool)pictureBox.Parent).Location; oldToolLocation = ((DepthExtensionPicTool)pictureBox.Parent).Location; oldToolTag = Convert.ToInt32(((DepthExtensionPicTool)pictureBox.Parent).Tag); mouseOffset = Control.MousePosition; } } /// /// 图片自定义控件的鼠标抬起事件 /// /// /// private void picTool_MouseUp(object sender, MouseEventArgs e) { if (!isMouseDown) return;//双击选择图片后可能异常进入该事件,不做处理 isMouseDown = false; PictureBox pictureBox = (PictureBox)sender; DepthExtensionPicTool depthExtensionPicTool = (DepthExtensionPicTool)pictureBox.Parent; List listDepthExtensionPicTool = new List(); foreach (Control C in this.panel2.Controls) { if (C is DepthExtensionPicTool && (DepthExtensionPicTool)C != depthExtensionPicTool) { listDepthExtensionPicTool.Add((DepthExtensionPicTool)C); } } if (listDepthExtensionPicTool != null && listDepthExtensionPicTool.Count > 0) { for (int i = 0; i < listDepthExtensionPicTool.Count; i++) { Point toolScreenLocation = listDepthExtensionPicTool[i].Location; int toolTag = Convert.ToInt32(listDepthExtensionPicTool[i].Tag); Rectangle toolScreenRectangle = new Rectangle(toolScreenLocation.X, toolScreenLocation.Y, 116, 116);//获得自定义控件对应的矩形区域 Point nowPoint = this.panel2.PointToClient(Control.MousePosition);//将屏幕鼠标点转换为控件坐标点 if (toolScreenRectangle.Contains(nowPoint) && toolTag != oldToolTag) { //替换两个控件的location和tag depthExtensionPicTool.Location = toolScreenLocation; depthExtensionPicTool.Tag = toolTag; listDepthExtensionPicTool[i].Location = oldToolLocation; listDepthExtensionPicTool[i].Tag = oldToolTag; this.panel2.Refresh(); return; } } } //如果鼠标点不与其他自定义控件重合,则当前拖动控件回到原始点 depthExtensionPicTool.Location = oldToolLocation; } /// /// 图片自定义控件的鼠标拖动事件 /// /// /// private void picTool_MouseMove(object sender, MouseEventArgs e) { int _x = 0; int _y = 0; if (isMouseDown) { Point pt = Control.MousePosition; _x = mouseOffset.X - pt.X; _y = mouseOffset.Y - pt.Y; PictureBox pictureBox = (PictureBox)sender; ((DepthExtensionPicTool)pictureBox.Parent).Cursor = Cursors.SizeAll; ((DepthExtensionPicTool)pictureBox.Parent).Location = new Point(picToolLocation.X - _x, picToolLocation.Y - _y); } } /// /// 第三步按钮 /// /// /// private void button3_Click(object sender, EventArgs e) { if (this.groupBox6.Visible && this.groupBox7.Visible) return; ChangeButtonStyle(this.button3, this.button1, this.button2); this.groupBox2.Visible = false; this.groupBox3.Visible = false; this.groupBoxStep2Operate.Visible = false; this.groupBox5.Visible = false; this.groupBox6.Visible = true; this.groupBox7.Visible = true; this.textBox3.Text = PdnResources.GetString("Menu.Image.Text") + "-" + PdnResources.GetString("Menu.ImageCollection.ImageStitching.Text") + "-" + stepNumber; this.pictureBox1.Image = null; this._mosaicsImage = null; //获取第二步的所有图片 List bitmapList = new List(); List tagList = new List(); foreach (Control C in this.panel2.Controls) { if (C is DepthExtensionPicTool) { DepthExtensionPicTool depthExtensionPicTool = (DepthExtensionPicTool)C; if (depthExtensionPicTool.pictureBox1.Image != null) { bitmapList.Add((Bitmap)(depthExtensionPicTool.pictureBox1.Image)); tagList.Add((int)depthExtensionPicTool.Tag); } } } if (bitmapList.Count < 2)//少于两张图时不做处理 { MessageBox.Show(PdnResources.GetString("Menu.Imporlessthatwopicturesunabletojoin.Text")); return; } else { OpenCvSharp.Mat[] mats = new OpenCvSharp.Mat[bitmapList.Count]; int index = 0; foreach (Bitmap bitmap in bitmapList) { var i = tagList[index] - 1; mats[index] = PaintDotNet.Camera.Tools.ToMat(bitmapList[index]); index++; } ////进行图片拼接 Boolean errorFlag = false; //OpenCvSharp.Mat mat = AdjustIntent.MatchPicByXFeatures2D(mats, out errorFlag); int colNum = this.tbxColunmN.Text == "" ? 0 : Convert.ToInt32(this.tbxColunmN.Text);//列数 double rate = (double)numOverlapRate.Value; OpenCvSharp.Mat mat = AdjustIntent.MatchPicOneByOne2D(mats, colNum, rate, out errorFlag/*, false*/); if (errorFlag || mat.Width < 1 || mat.Height < 1)//宽高大于0代表拼接成功,只能操作可拼接的图片 { MessageBox.Show(PdnResources.GetString("Menu.ImageMosaicfailed.Text")); return; } _mosaicsImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat); if (_mosaicsImage != null) { if (_mosaicsImage.Width > this.pictureBox1.Size.Width || _mosaicsImage.Height > this.pictureBox1.Size.Height) { this.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; } else { this.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage; } this.pictureBox1.Image = _mosaicsImage; } } _lastPoint = new Point(0, 0); _isFirst = true; } /// /// 修改第X步的按钮样式 /// /// 要修改的按钮 /// 要恢复的按钮1 /// 要恢复的按钮2 private void ChangeButtonStyle(Button displayButton, Button hideButton1, Button hideButton2) { hideButton1.BackColor = Color.FromArgb(255, 240, 240, 240); hideButton1.ForeColor = Color.FromArgb(255, 0, 0, 0); hideButton1.FlatStyle = FlatStyle.Standard; hideButton1.FlatAppearance.BorderSize = 1; hideButton2.BackColor = Color.FromArgb(255, 240, 240, 240); hideButton2.ForeColor = Color.FromArgb(255, 0, 0, 0); hideButton2.FlatStyle = FlatStyle.Standard; hideButton2.FlatAppearance.BorderSize = 1; displayButton.BackColor = Color.Gray; displayButton.ForeColor = Color.White; displayButton.FlatStyle = FlatStyle.Flat; displayButton.FlatAppearance.BorderSize = 0; } /// /// 绘制删除图标 /// /// /// private void panelDel_Paint(object sender, PaintEventArgs e) { Image deleteImg = PdnResources.GetImageResource("Images.ImageStrip.CloseButton.Hot.png").Reference;//从项目中随便找了一个红色的删除图片 if (deleteImg != null) { Graphics g = e.Graphics; g.DrawImage(deleteImg, 0, 0); } } /// /// 绘制添加功能的十字线 /// /// /// private void panelAdd_Paint(object sender, PaintEventArgs e) { Panel panel = (Panel)sender; Size panelSize = panel.Size; Graphics g = e.Graphics; Pen linePen = new Pen(Color.Black); linePen.Width = 3; g.DrawLine(linePen, new Point(0, panelSize.Height / 2), new Point(panelSize.Width, panelSize.Height / 2)); g.DrawLine(linePen, new Point(panelSize.Width / 2, 0), new Point(panelSize.Width / 2, panelSize.Height)); linePen.Dispose(); } /// /// 点击添加标志 /// /// /// private void panelAdd_Click(object sender, EventArgs e) { Bitmap bitmap = ChooseImageFromHardDisk(); if (bitmap != null) { Panel panel = (Panel)sender; DepthExtensionPicTool parentTool = (DepthExtensionPicTool)panel.Parent; if (bitmap.Width > parentTool.pictureBox1.Size.Width || bitmap.Height > parentTool.pictureBox1.Size.Height) { parentTool.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; } else { parentTool.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage; } parentTool.pictureBox1.Image = bitmap; parentTool.panel2.Visible = false; parentTool.panel1.Visible = true; } } /// /// 点击删除图标 /// /// /// private void panelDel_Click(object sender, EventArgs e) { Panel panel = (Panel)sender; DepthExtensionPicTool parentTool = (DepthExtensionPicTool)panel.Parent; if (parentTool.pictureBox1.Image != null) { parentTool.pictureBox1.Image = null; parentTool.panel2.Visible = true; parentTool.panel1.Visible = false; } } /// /// 点击倒置按钮 /// /// /// private void convertButton_Click(object sender, EventArgs e) { Button convertBtn = (Button)sender; int rowNum = 0; if (convertBtn.Tag != null && convertBtn.Tag.ToString().Length > 0) { rowNum = Convert.ToInt32(convertBtn.Tag.ToString());//button的tag值确定是第几行 } if (rowNum > 0) { int colNum = this.tbxColunmN.Text == "" ? 0 : Convert.ToInt32(this.tbxColunmN.Text);//列数 //取得点击按钮所在行的图片自定义控件tag的最大值与最小值 int minTag = colNum * (rowNum - 1) + 1; int maxTag = colNum * rowNum; //取得所有图片自定义控件的list List picToolList = new List(); foreach (Control C in this.panel2.Controls) { if (C is DepthExtensionPicTool) { picToolList.Add((DepthExtensionPicTool)C); } } //取得tag值所对应的图片自定义控件对象 List convertPicToolList = picToolList.FindAll(a => Convert.ToInt32(a.Tag) >= minTag && Convert.ToInt32(a.Tag) <= maxTag); convertPicToolList = convertPicToolList.OrderBy(a => a.Location.X).ToList();//按location重新排序 List locationPoint = new List(convertPicToolList.Select(a => a.Location).ToList());//取得这些对象的location //反转后再重新赋回去 locationPoint.Reverse(); for (int j = 0; j < convertPicToolList.Count; j++) { convertPicToolList[j].Location = locationPoint[j]; } for (int j = 0; j < convertPicToolList.Count / 2; j++) { int tag1 = (int)convertPicToolList[j].Tag; convertPicToolList[j].Tag = (int)convertPicToolList[convertPicToolList.Count - j - 1].Tag; convertPicToolList[convertPicToolList.Count - j - 1].Tag = tag1; } } } /// /// 保存按钮 /// /// /// private void button8_Click(object sender, EventArgs e) { if (this.pictureBox1.Image != null && _mosaicsImage != null) { double widthRatio = imageRect.Width / (_mosaicsImage.Width * 1d);//缩略图与原图的宽度比 double heightRatio = imageRect.Height / (_mosaicsImage.Height * 1d);//缩略图与原图的高度比 int xc = (this.pictureBox1.Width - this.imageRect.Width) / 2;//缩略图横坐标与控件原点的偏移量 int yc = (this.pictureBox1.Height - this.imageRect.Height) / 2;//缩略图纵坐标与控件原点的偏移量 int cutX = Convert.ToInt32((zoomRect.X - xc) / widthRatio); int cutY = Convert.ToInt32((zoomRect.Y - yc) / heightRatio); int cutWidth = Convert.ToInt32(zoomRect.Width / widthRatio); int cutHeight = Convert.ToInt32(zoomRect.Height / heightRatio); Bitmap cutBitmap = DrawRulerHelper.KiCut(new Bitmap(this.pictureBox1.Image), cutX, cutY, cutWidth, cutHeight); if (cutBitmap != null) { DocumentWorkspace dw = appWorkspace.AddNewDocumentWorkspace(); Document document = Document.FromImageMat(Camera.Tools.ToMat(cutBitmap)); dw.Document = document; dw.xmlSaveModel = Startup.instance.ruleDB; dw.InitRulerInfo(); dw.fileText = this.textBox3.Text; appWorkspace.ActiveDocumentWorkspace = dw; Startup.instance.step_length += 1; stepNumber = "00" + Startup.instance.step_length; this.textBox3.Text = PdnResources.GetString("Menu.Image.Text") + "-" + PdnResources.GetString("Menu.ImageCollection.ImageStitching.Text") + "-" + stepNumber; } } } /// /// 绘制picturebox中的矩形框 /// /// /// private void pictureBox1_Paint(object sender, PaintEventArgs e) { if (this.pictureBox1.Image != null) { Pen rectPen = new Pen(Color.LightGreen); rectPen.Width = 3; if (_isFirst) { //获取缩略图对应矩形 PropertyInfo _ImageRectanglePropert = this.pictureBox1.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic); imageRect = (Rectangle)_ImageRectanglePropert.GetValue(this.pictureBox1, null); zoomRect = new Rectangle(imageRect.X, imageRect.Y, imageRect.Width, imageRect.Height); } e.Graphics.DrawRectangle(rectPen, zoomRect.X, zoomRect.Y, zoomRect.Width - 1, zoomRect.Height - 1); e.Graphics.FillRectangle(new SolidBrush(Color.Black), new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 7, 7)); rectPen.Dispose(); } } /// /// 矩形框的选中 /// /// /// private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { _lastPoint.X = e.X; _lastPoint.Y = e.Y; //是否平移 if (zoomRect.Contains(e.Location) && !new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 7, 7).Contains(e.Location)) isMoved = true; else isMoved = false; //是否调整大小 if (new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 7, 7).Contains(e.Location)) isResized = true; else isResized = false; } /// /// 矩形框的拖动和改变大小 /// /// /// private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { //修改鼠标形状 this.pictureBox1.Cursor = Cursors.Default; if (zoomRect != null) { if (zoomRect.Contains(e.Location) && !new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 7, 7).Contains(e.Location)) { this.pictureBox1.Cursor = Cursors.SizeAll; } if (new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 7, 7).Contains(e.Location)) { this.pictureBox1.Cursor = Cursors.SizeNWSE; } } if (e.Button != MouseButtons.Left) return; //拖拽 if (zoomRect != null && isMoved) { _isFirst = false; Point p = e.Location; int dx = p.X - _lastPoint.X; int dy = p.Y - _lastPoint.Y; _lastPoint.X = p.X; _lastPoint.Y = p.Y; zoomRect.X += dx; zoomRect.Y += dy; //控制矩形框不超过缩略图尺寸 int xc = (this.pictureBox1.Width - this.imageRect.Width) / 2; int yc = (this.pictureBox1.Height - this.imageRect.Height) / 2; if (zoomRect.X < xc) zoomRect.X = xc; if (zoomRect.Y < yc) zoomRect.Y = yc; if (zoomRect.X + zoomRect.Width > imageRect.Width + xc) zoomRect.X = imageRect.Width - zoomRect.Width + xc; if (zoomRect.Y + zoomRect.Height > imageRect.Height + yc) zoomRect.Y = imageRect.Height - zoomRect.Height + yc; this.pictureBox1.Refresh(); } //调整大小 if (zoomRect != null && isResized) { _isFirst = false; Point p = e.Location; //不允许超出矩形框的原点 if (p.X < zoomRect.X + 5) { p.X = zoomRect.X + 5; } if (p.Y < zoomRect.Y + 5) { p.Y = zoomRect.Y + 5; } //修改矩形框尺寸 int top = zoomRect.Top; int left = zoomRect.Left; int right = zoomRect.Right; int bottom = zoomRect.Bottom; right = p.X; bottom = p.Y; zoomRect = new Rectangle(left, top, right - left, bottom - top); //控制矩形框不超过缩略图尺寸 int xc = (this.pictureBox1.Width - this.imageRect.Width) / 2; int yc = (this.pictureBox1.Height - this.imageRect.Height) / 2; if (zoomRect.X < xc) zoomRect.X = xc; if (zoomRect.Y < yc) zoomRect.Y = yc; if (zoomRect.X + zoomRect.Width > imageRect.Width + xc) zoomRect.Width = imageRect.Width + xc - zoomRect.X; if (zoomRect.Y + zoomRect.Height > imageRect.Height + yc) zoomRect.Height = imageRect.Height + yc - zoomRect.Y; this.pictureBox1.Refresh(); } } /// /// 返回按钮 /// /// /// private void button5_Click(object sender, EventArgs e) { //第二步 if (this.groupBox6.Visible && this.groupBox7.Visible) { this.button2.PerformClick(); return; } //第一步 if (this.groupBoxStep2Operate.Visible && this.groupBox5.Visible) { this.button1.PerformClick(); return; } } /// /// 下一步按钮 /// /// /// private void button4_Click(object sender, EventArgs e) { //第二步 if (this.groupBox2.Visible && this.groupBox3.Visible) { this.button2.PerformClick(); return; } //第三步 if (this.groupBoxStep2Operate.Visible && this.groupBox5.Visible) { this.button3.PerformClick(); return; } } } }