From b2fbc1d49bd3546553be23fee545b01a8c16f01c Mon Sep 17 00:00:00 2001 From: cloud301530 <2690004082@qq.com> Date: Tue, 26 Nov 2024 21:01:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=94=BB=E7=9F=A9=E5=BD=A2RO?= =?UTF-8?q?I?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PBAnaly/Module/BioanalysisMannage.cs | 66 ++++++++++++++++++- .../UI/BioanayImagePaletteForm.Designer.cs | 13 ++-- 2 files changed, 71 insertions(+), 8 deletions(-) diff --git a/src/PBAnaly/Module/BioanalysisMannage.cs b/src/PBAnaly/Module/BioanalysisMannage.cs index d77f879..acd6caa 100644 --- a/src/PBAnaly/Module/BioanalysisMannage.cs +++ b/src/PBAnaly/Module/BioanalysisMannage.cs @@ -81,6 +81,13 @@ namespace PBAnaly.Module private const int CircleRadius = 5; private bool lineOn =false; private bool drawLine = false; + + private bool CircleOn = false; + private bool rectOn = false; + private List rectangles = new List(); // 存储所有绘制完成的矩形 + private System.Drawing.Rectangle? currentRectangle = null; // 当前正在绘制的矩形 + private System.Drawing.Point leftTopPoint; // 矩形左上角的起始点 + private bool drawRect = false; // 是否正在绘制 private System.Drawing.Point startPoint = new System.Drawing.Point(-10, 0); private System.Drawing.Point endPoint = new System.Drawing.Point(-10, 0); @@ -355,6 +362,7 @@ namespace PBAnaly.Module imagePaletteForm.nud_colorMin.ValueChanged += Nud_colorMin_ValueChanged; imagePaletteForm.cb_colortable.SelectedIndexChanged += Cb_colortable_SelectedIndexChanged; + imagePanel.cb_scientific.CheckedChanged += Cb_scientific_CheckedChanged; @@ -369,6 +377,7 @@ namespace PBAnaly.Module imagePanel.wdb_title.MouseDown += Wdb_title_Click; + imagePaletteForm.hpb_rect.Click += hpb_rect_Click; } @@ -618,6 +627,7 @@ namespace PBAnaly.Module { Graphics g = e.Graphics; + // 绘制直线 if ((startPoint != System.Drawing.Point.Empty && endPoint != System.Drawing.Point.Empty)) { @@ -629,6 +639,21 @@ namespace PBAnaly.Module ImageProcess.DrawCircle(g, srart, CircleRadius, Pens.Blue, Brushes.LightBlue); ImageProcess.DrawCircle(g, end, CircleRadius, Pens.Blue, Brushes.LightBlue); } + if(leftTopPoint != System.Drawing.Point.Empty) + { + // 绘制所有已绘制的矩形 + foreach (var rect in rectangles) + { + e.Graphics.DrawRectangle(Pens.Blue, rect); + } + + // 绘制当前正在绘制的矩形 + if (currentRectangle.HasValue) + { + e.Graphics.DrawRectangle(Pens.Red, currentRectangle.Value); + } + } + } private void Image_pl_MouseUp(object sender, MouseEventArgs e) @@ -654,7 +679,21 @@ namespace PBAnaly.Module imagePaletteForm.flb_act_mm.Text = value.ToString() + " mm"; imagePaletteForm.flb_act_mm.Refresh(); } - + else if(drawRect && e.Button == MouseButtons.Left) + { + if (drawRect && currentRectangle.HasValue) + { + // 完成绘制并保存矩形 + rectangles.Add(currentRectangle.Value); + currentRectangle = null; + drawRect = false; + } + + drawRect = false; + rectOn = false; + + + } } @@ -701,8 +740,19 @@ namespace PBAnaly.Module { imagePanel.image_pl.Cursor = Cursors.Hand; } + else if(drawRect && e.Button == MouseButtons.Left) + { + // 动态调整矩形大小 + int x = Math.Min(leftTopPoint.X, e.X); + int y = Math.Min(leftTopPoint.Y, e.Y); + int width = Math.Abs(e.X - leftTopPoint.X); + int height = Math.Abs(e.Y - leftTopPoint.Y); + + currentRectangle = new System.Drawing.Rectangle(x, y, width, height); + imagePanel.image_pl.Invalidate(); // 触发重绘 + } - else + else { imagePanel.image_pl.Cursor = Cursors.Default; } @@ -742,6 +792,13 @@ namespace PBAnaly.Module isEndCircleDragged = true; } + else if (rectOn) + { + // 开始绘制新矩形 + drawRect = true; + leftTopPoint = e.Location; + currentRectangle = new System.Drawing.Rectangle(e.X, e.Y, 0, 0); + } } else if (e.Button == MouseButtons.Right) { @@ -763,6 +820,11 @@ namespace PBAnaly.Module { lineOn = true; } + + private void hpb_rect_Click(object sender, EventArgs e) + { + rectOn = true; + } #endregion #endregion #region 对外接口 diff --git a/src/PBAnaly/UI/BioanayImagePaletteForm.Designer.cs b/src/PBAnaly/UI/BioanayImagePaletteForm.Designer.cs index a5dcdc0..63bb7f9 100644 --- a/src/PBAnaly/UI/BioanayImagePaletteForm.Designer.cs +++ b/src/PBAnaly/UI/BioanayImagePaletteForm.Designer.cs @@ -358,7 +358,7 @@ this.tableLayoutPanel3.RowCount = 2; this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 34F)); this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel3.Size = new System.Drawing.Size(268, 113); + this.tableLayoutPanel3.Size = new System.Drawing.Size(266, 113); this.tableLayoutPanel3.TabIndex = 0; // // hpb_circe @@ -388,16 +388,17 @@ this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; this.panel2.Location = new System.Drawing.Point(3, 37); this.panel2.Name = "panel2"; - this.panel2.Size = new System.Drawing.Size(262, 73); + this.panel2.Size = new System.Drawing.Size(260, 73); this.panel2.TabIndex = 14; this.panel2.Text = "panel2"; // // collapseItem2 // this.collapseItem2.Controls.Add(this.tableLayoutPanel3); - this.collapseItem2.Location = new System.Drawing.Point(-268, -113); + this.collapseItem2.Expand = true; + this.collapseItem2.Location = new System.Drawing.Point(19, 433); this.collapseItem2.Name = "collapseItem2"; - this.collapseItem2.Size = new System.Drawing.Size(268, 113); + this.collapseItem2.Size = new System.Drawing.Size(266, 113); this.collapseItem2.TabIndex = 1; this.collapseItem2.Text = "ROI工具"; // @@ -660,7 +661,7 @@ // collapseItem3 // this.collapseItem3.Expand = true; - this.collapseItem3.Location = new System.Drawing.Point(19, 473); + this.collapseItem3.Location = new System.Drawing.Point(19, 618); this.collapseItem3.Margin = new System.Windows.Forms.Padding(2); this.collapseItem3.Name = "collapseItem3"; this.collapseItem3.Size = new System.Drawing.Size(266, 154); @@ -718,7 +719,6 @@ private ReaLTaiizor.Controls.HopePictureBox hpb_wand; private ReaLTaiizor.Controls.HopePictureBox hpb_xianduan; private ReaLTaiizor.Controls.FoxTextBox ftb_r; - private ReaLTaiizor.Controls.HopePictureBox hpb_rect; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel3; private ReaLTaiizor.Controls.HopePictureBox hpb_circe; private AntdUI.Panel panel2; @@ -739,5 +739,6 @@ public System.Windows.Forms.ComboBox cb_colortable; public ReaLTaiizor.Controls.HopePictureBox hpb_line; public ReaLTaiizor.Controls.FoxLabel flb_act_mm; + public ReaLTaiizor.Controls.HopePictureBox hpb_rect; } } \ No newline at end of file