添加温差图例按钮(btnAddTempDiff、btnDeleteTempDiff)及其事件处理方法

This commit is contained in:
zqm
2025-11-10 10:51:17 +08:00
parent 62c16354c7
commit 7db4c5366c
2 changed files with 85 additions and 1 deletions

View File

@@ -38,6 +38,8 @@ namespace JoyD.Windows.CS
this.btnSelectColor = new System.Windows.Forms.ToolStripButton(); this.btnSelectColor = new System.Windows.Forms.ToolStripButton();
this.btnDeleteRegion = new System.Windows.Forms.ToolStripButton(); this.btnDeleteRegion = new System.Windows.Forms.ToolStripButton();
this.btnDrawTempDiff = new System.Windows.Forms.ToolStripButton(); this.btnDrawTempDiff = new System.Windows.Forms.ToolStripButton();
this.btnAddTempDiff = new System.Windows.Forms.ToolStripButton();
this.btnDeleteTempDiff = new System.Windows.Forms.ToolStripButton();
((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
this.splitContainer.Panel1.SuspendLayout(); this.splitContainer.Panel1.SuspendLayout();
this.splitContainer.Panel2.SuspendLayout(); this.splitContainer.Panel2.SuspendLayout();
@@ -134,7 +136,9 @@ namespace JoyD.Windows.CS
this.btnDrawRegion, this.btnDrawRegion,
this.btnSelectColor, this.btnSelectColor,
this.btnDeleteRegion, this.btnDeleteRegion,
this.btnDrawTempDiff}); this.btnDrawTempDiff,
this.btnAddTempDiff,
this.btnDeleteTempDiff});
this.toolStrip.Location = new System.Drawing.Point(3, 0); this.toolStrip.Location = new System.Drawing.Point(3, 0);
this.toolStrip.Name = "toolStrip"; this.toolStrip.Name = "toolStrip";
this.toolStrip.Size = new System.Drawing.Size(104, 25); this.toolStrip.Size = new System.Drawing.Size(104, 25);
@@ -182,6 +186,26 @@ namespace JoyD.Windows.CS
this.btnDrawTempDiff.ToolTipText = "绘制温差图"; this.btnDrawTempDiff.ToolTipText = "绘制温差图";
this.btnDrawTempDiff.Click += new System.EventHandler(this.BtnDrawTempDiff_Click); this.btnDrawTempDiff.Click += new System.EventHandler(this.BtnDrawTempDiff_Click);
// //
// btnAddTempDiff
//
this.btnAddTempDiff.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.btnAddTempDiff.ImageTransparentColor = System.Drawing.Color.Transparent;
this.btnAddTempDiff.Name = "btnAddTempDiff";
this.btnAddTempDiff.Size = new System.Drawing.Size(23, 22);
this.btnAddTempDiff.Text = "添加温差图例";
this.btnAddTempDiff.ToolTipText = "添加温差图例";
this.btnAddTempDiff.Click += new System.EventHandler(this.BtnAddTempDiff_Click);
//
// btnDeleteTempDiff
//
this.btnDeleteTempDiff.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.btnDeleteTempDiff.ImageTransparentColor = System.Drawing.Color.Transparent;
this.btnDeleteTempDiff.Name = "btnDeleteTempDiff";
this.btnDeleteTempDiff.Size = new System.Drawing.Size(23, 22);
this.btnDeleteTempDiff.Text = "删除温差图例";
this.btnDeleteTempDiff.ToolTipText = "删除温差图例";
this.btnDeleteTempDiff.Click += new System.EventHandler(this.BtnDeleteTempDiff_Click);
//
// Setting // Setting
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
@@ -222,6 +246,8 @@ namespace JoyD.Windows.CS
private System.Windows.Forms.ToolStripButton btnSelectColor; private System.Windows.Forms.ToolStripButton btnSelectColor;
private System.Windows.Forms.ToolStripButton btnDeleteRegion; private System.Windows.Forms.ToolStripButton btnDeleteRegion;
private System.Windows.Forms.ToolStripButton btnDrawTempDiff; private System.Windows.Forms.ToolStripButton btnDrawTempDiff;
private System.Windows.Forms.ToolStripButton btnAddTempDiff;
private System.Windows.Forms.ToolStripButton btnDeleteTempDiff;
private System.Windows.Forms.DataGridView dataGridViewTempDiff; private System.Windows.Forms.DataGridView dataGridViewTempDiff;
} }
} }

View File

@@ -69,6 +69,9 @@ namespace JoyD.Windows.CS
btnDeleteRegion.Visible = false; btnDeleteRegion.Visible = false;
// 初始状态/就绪状态下显示温差图按钮 // 初始状态/就绪状态下显示温差图按钮
btnDrawTempDiff.Visible = true; btnDrawTempDiff.Visible = true;
// 初始状态下隐藏添加和删除温差图例按钮
btnAddTempDiff.Visible = false;
btnDeleteTempDiff.Visible = false;
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -454,6 +457,8 @@ namespace JoyD.Windows.CS
btnSelectColor.Visible = false; // 隐藏颜色选择按钮 btnSelectColor.Visible = false; // 隐藏颜色选择按钮
btnDeleteRegion.Visible = false; // 隐藏删除区域按钮 btnDeleteRegion.Visible = false; // 隐藏删除区域按钮
dataGridViewTempDiff.Visible = true; // 显示温差图例表格 dataGridViewTempDiff.Visible = true; // 显示温差图例表格
btnAddTempDiff.Visible = true; // 显示添加温差图例按钮
btnDeleteTempDiff.Visible = true; // 显示删除温差图例按钮
break; break;
} }
} }
@@ -520,6 +525,59 @@ namespace JoyD.Windows.CS
/// <summary> /// <summary>
/// 绘制区域按钮点击事件 /// 绘制区域按钮点击事件
/// </summary> /// </summary>
/// <summary>
/// 添加温差图例按钮点击事件
/// </summary>
private void BtnAddTempDiff_Click(object sender, EventArgs e)
{
try
{
// 添加新的温差图例
AddTempDiffRow();
}
catch (Exception ex)
{
Console.WriteLine("添加温差图例失败: " + ex.Message);
}
}
/// <summary>
/// 删除温差图例按钮点击事件
/// </summary>
private void BtnDeleteTempDiff_Click(object sender, EventArgs e)
{
try
{
// 检查是否有选中的行
if (dataGridViewTempDiff.SelectedRows.Count > 0)
{
// 获取选中行的索引
int selectedRowIndex = dataGridViewTempDiff.SelectedRows[0].Index;
// 从数据集合中删除该行数据
if (selectedRowIndex >= 0 && selectedRowIndex < tempDiffData.Count)
{
tempDiffData.RemoveAt(selectedRowIndex);
// 从DataGridView中删除该行
dataGridViewTempDiff.Rows.RemoveAt(selectedRowIndex);
}
}
else
{
// 如果没有选中行,默认删除最后一行
if (tempDiffData.Count > 0)
{
tempDiffData.RemoveAt(tempDiffData.Count - 1);
dataGridViewTempDiff.Rows.RemoveAt(dataGridViewTempDiff.Rows.Count - 1);
}
}
}
catch (Exception ex)
{
Console.WriteLine("删除温差图例失败: " + ex.Message);
}
}
private void BtnDrawRegion_Click(object sender, EventArgs e) private void BtnDrawRegion_Click(object sender, EventArgs e)
{ {
_isDrawingMode = btnDrawRegion.Checked; _isDrawingMode = btnDrawRegion.Checked;