设置工具条按钮点击事件及调整布局
This commit is contained in:
@@ -157,4 +157,23 @@
|
||||
11. 当选中区域时,btnDeleteRegion用于删除该区域,删除后btnSelectColor隐藏,btnDrawRegion显示。
|
||||
12. 当选中区域时,鼠标移动到八个句柄上,显示对应的光标,用于调整区域大小。
|
||||
13. 当选中区域时,鼠标可以移动区域,用于调整区域位置。
|
||||
14. 当就绪状态时,工具栏显示绘制温差图按钮(btnDrawTempDiff)
|
||||
14. 当选中区域时,右击鼠标,退出选中状态,转为就绪状态
|
||||
15. 当就绪状态时,工具栏显示绘制温差图按钮(btnDrawTempDiff)
|
||||
16. 当绘制温差图按钮按下时,进入绘制温差图状态
|
||||
17. 当绘制温差图状态时,右击鼠标进入就绪状态
|
||||
|
||||
#### 配置状态说明
|
||||
1. 初始状态/就绪状态:
|
||||
- 显示btnDrawRegion和btnDrawTempDiff按钮
|
||||
- 隐藏btnSelectColor、btnDeleteRegion按钮
|
||||
2. 选中区域状态:
|
||||
- 显示btnDeleteRegion和btnSelectColor按钮
|
||||
- 隐藏btnDrawRegion和btnDrawTempDiff按钮
|
||||
3. 绘制状态:
|
||||
- 显示btnSelectColor按钮
|
||||
- 显示btnDrawRegion按钮
|
||||
- 隐藏btnDeleteRegion按钮
|
||||
- 隐藏btnDrawTempDiff按钮
|
||||
4. 绘制温差图状态:
|
||||
- 显示btnDrawTempDiff按钮
|
||||
- 隐藏btnSelectColor、btnDeleteRegion、btnDrawRegion按钮
|
||||
@@ -28,37 +28,27 @@ namespace JoyD.Windows.CS
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.btnDrawTempDiff = new System.Windows.Forms.ToolStripButton();
|
||||
this.splitContainer = new System.Windows.Forms.SplitContainer();
|
||||
this.groupBoxTempDisplay = new System.Windows.Forms.GroupBox();
|
||||
this.picBoxTemp = new System.Windows.Forms.PictureBox();
|
||||
this.toolStripContainer = new System.Windows.Forms.ToolStripContainer();
|
||||
this.tempDiffToolStrip = new System.Windows.Forms.ToolStrip();
|
||||
this.toolStrip = new System.Windows.Forms.ToolStrip();
|
||||
this.btnDrawRegion = new System.Windows.Forms.ToolStripButton();
|
||||
this.btnSelectColor = new System.Windows.Forms.ToolStripButton();
|
||||
this.btnDeleteRegion = new System.Windows.Forms.ToolStripButton();
|
||||
this.tempDiffToolStrip = new System.Windows.Forms.ToolStrip();
|
||||
this.btnDrawTempDiff = new System.Windows.Forms.ToolStripButton();
|
||||
((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
|
||||
this.splitContainer.Panel1.SuspendLayout();
|
||||
this.splitContainer.Panel2.SuspendLayout();
|
||||
this.splitContainer.SuspendLayout();
|
||||
this.groupBoxTempDisplay.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.picBoxTemp)).BeginInit();
|
||||
this.toolStripContainer.ContentPanel.SuspendLayout();
|
||||
this.toolStripContainer.TopToolStripPanel.SuspendLayout();
|
||||
this.toolStripContainer.SuspendLayout();
|
||||
this.toolStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// btnDrawTempDiff
|
||||
//
|
||||
this.btnDrawTempDiff.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
|
||||
this.btnDrawTempDiff.ImageTransparentColor = System.Drawing.Color.Transparent;
|
||||
this.btnDrawTempDiff.Name = "btnDrawTempDiff";
|
||||
this.btnDrawTempDiff.Size = new System.Drawing.Size(23, 4);
|
||||
this.btnDrawTempDiff.Text = "绘制温差图";
|
||||
this.btnDrawTempDiff.ToolTipText = "绘制温差图";
|
||||
this.btnDrawTempDiff.Click += new System.EventHandler(this.BtnDrawTempDiff_Click);
|
||||
//
|
||||
// splitContainer
|
||||
//
|
||||
this.splitContainer.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
@@ -108,8 +98,7 @@ namespace JoyD.Windows.CS
|
||||
//
|
||||
// toolStripContainer.ContentPanel
|
||||
//
|
||||
this.toolStripContainer.ContentPanel.Controls.Add(this.tempDiffToolStrip);
|
||||
this.toolStripContainer.ContentPanel.Controls.Add(this.toolStrip);
|
||||
this.toolStripContainer.ContentPanel.AutoScroll = true;
|
||||
this.toolStripContainer.ContentPanel.Size = new System.Drawing.Size(174, 425);
|
||||
this.toolStripContainer.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.toolStripContainer.Location = new System.Drawing.Point(0, 0);
|
||||
@@ -118,22 +107,36 @@ namespace JoyD.Windows.CS
|
||||
this.toolStripContainer.TabIndex = 0;
|
||||
this.toolStripContainer.Text = "toolStripContainer";
|
||||
//
|
||||
// toolStripContainer.TopToolStripPanel
|
||||
//
|
||||
this.toolStripContainer.TopToolStripPanel.Controls.Add(this.toolStrip);
|
||||
this.toolStripContainer.TopToolStripPanel.Controls.Add(this.tempDiffToolStrip);
|
||||
//
|
||||
// tempDiffToolStrip
|
||||
//
|
||||
this.tempDiffToolStrip.AllowDrop = true;
|
||||
this.tempDiffToolStrip.Dock = System.Windows.Forms.DockStyle.None;
|
||||
this.tempDiffToolStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||
this.tempDiffToolStrip.Location = new System.Drawing.Point(110, 0);
|
||||
this.tempDiffToolStrip.Name = "tempDiffToolStrip";
|
||||
this.tempDiffToolStrip.Size = new System.Drawing.Size(51, 25);
|
||||
this.tempDiffToolStrip.TabIndex = 4;
|
||||
this.tempDiffToolStrip.Text = "温差图例";
|
||||
//
|
||||
// toolStrip
|
||||
//
|
||||
this.toolStrip.AllowDrop = true;
|
||||
this.toolStrip.Dock = System.Windows.Forms.DockStyle.None;
|
||||
this.toolStrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Visible;
|
||||
this.toolStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||
this.toolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.btnDrawRegion,
|
||||
this.btnSelectColor,
|
||||
this.btnDeleteRegion,
|
||||
this.btnDrawTempDiff});
|
||||
this.toolStrip.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.Flow;
|
||||
this.toolStrip.Location = new System.Drawing.Point(22, 96);
|
||||
this.toolStrip.Location = new System.Drawing.Point(3, 0);
|
||||
this.toolStrip.Name = "toolStrip";
|
||||
this.toolStrip.Size = new System.Drawing.Size(93, 7);
|
||||
this.toolStrip.TabIndex = 1;
|
||||
this.toolStrip.Size = new System.Drawing.Size(104, 25);
|
||||
this.toolStrip.TabIndex = 3;
|
||||
this.toolStrip.Text = "工具条";
|
||||
//
|
||||
// btnDrawRegion
|
||||
@@ -142,7 +145,7 @@ namespace JoyD.Windows.CS
|
||||
this.btnDrawRegion.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
|
||||
this.btnDrawRegion.ImageTransparentColor = System.Drawing.Color.Transparent;
|
||||
this.btnDrawRegion.Name = "btnDrawRegion";
|
||||
this.btnDrawRegion.Size = new System.Drawing.Size(23, 4);
|
||||
this.btnDrawRegion.Size = new System.Drawing.Size(23, 22);
|
||||
this.btnDrawRegion.Text = "画框";
|
||||
this.btnDrawRegion.ToolTipText = "绘制温度检测区域(点击开启/关闭)";
|
||||
this.btnDrawRegion.Click += new System.EventHandler(this.BtnDrawRegion_Click);
|
||||
@@ -152,7 +155,7 @@ namespace JoyD.Windows.CS
|
||||
this.btnSelectColor.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
|
||||
this.btnSelectColor.ImageTransparentColor = System.Drawing.Color.Transparent;
|
||||
this.btnSelectColor.Name = "btnSelectColor";
|
||||
this.btnSelectColor.Size = new System.Drawing.Size(23, 4);
|
||||
this.btnSelectColor.Size = new System.Drawing.Size(23, 22);
|
||||
this.btnSelectColor.Text = "选择颜色";
|
||||
this.btnSelectColor.ToolTipText = "选择绘制区域的颜色(点击更换颜色)";
|
||||
this.btnSelectColor.Click += new System.EventHandler(this.BtnSelectColor_Click);
|
||||
@@ -162,22 +165,20 @@ namespace JoyD.Windows.CS
|
||||
this.btnDeleteRegion.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
|
||||
this.btnDeleteRegion.ImageTransparentColor = System.Drawing.Color.Transparent;
|
||||
this.btnDeleteRegion.Name = "btnDeleteRegion";
|
||||
this.btnDeleteRegion.Size = new System.Drawing.Size(23, 4);
|
||||
this.btnDeleteRegion.Size = new System.Drawing.Size(23, 22);
|
||||
this.btnDeleteRegion.Text = "删除区域";
|
||||
this.btnDeleteRegion.ToolTipText = "删除选中的区域";
|
||||
this.btnDeleteRegion.Click += new System.EventHandler(this.BtnDeleteRegion_Click);
|
||||
//
|
||||
// tempDiffToolStrip
|
||||
// btnDrawTempDiff
|
||||
//
|
||||
this.tempDiffToolStrip.AllowDrop = true;
|
||||
this.tempDiffToolStrip.Dock = System.Windows.Forms.DockStyle.None;
|
||||
this.tempDiffToolStrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Visible;
|
||||
this.tempDiffToolStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||
this.tempDiffToolStrip.Location = new System.Drawing.Point(54, 140);
|
||||
this.tempDiffToolStrip.Name = "tempDiffToolStrip";
|
||||
this.tempDiffToolStrip.Size = new System.Drawing.Size(51, 25);
|
||||
this.tempDiffToolStrip.TabIndex = 2;
|
||||
this.tempDiffToolStrip.Text = "温差图例";
|
||||
this.btnDrawTempDiff.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
|
||||
this.btnDrawTempDiff.ImageTransparentColor = System.Drawing.Color.Transparent;
|
||||
this.btnDrawTempDiff.Name = "btnDrawTempDiff";
|
||||
this.btnDrawTempDiff.Size = new System.Drawing.Size(23, 22);
|
||||
this.btnDrawTempDiff.Text = "绘制温差图";
|
||||
this.btnDrawTempDiff.ToolTipText = "绘制温差图";
|
||||
this.btnDrawTempDiff.Click += new System.EventHandler(this.BtnDrawTempDiff_Click);
|
||||
//
|
||||
// Setting
|
||||
//
|
||||
@@ -196,8 +197,8 @@ namespace JoyD.Windows.CS
|
||||
this.splitContainer.ResumeLayout(false);
|
||||
this.groupBoxTempDisplay.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.picBoxTemp)).EndInit();
|
||||
this.toolStripContainer.ContentPanel.ResumeLayout(false);
|
||||
this.toolStripContainer.ContentPanel.PerformLayout();
|
||||
this.toolStripContainer.TopToolStripPanel.ResumeLayout(false);
|
||||
this.toolStripContainer.TopToolStripPanel.PerformLayout();
|
||||
this.toolStripContainer.ResumeLayout(false);
|
||||
this.toolStripContainer.PerformLayout();
|
||||
this.toolStrip.ResumeLayout(false);
|
||||
@@ -212,11 +213,11 @@ namespace JoyD.Windows.CS
|
||||
private System.Windows.Forms.GroupBox groupBoxTempDisplay;
|
||||
private System.Windows.Forms.PictureBox picBoxTemp;
|
||||
private System.Windows.Forms.ToolStripContainer toolStripContainer;
|
||||
private System.Windows.Forms.ToolStrip tempDiffToolStrip;
|
||||
private System.Windows.Forms.ToolStrip toolStrip;
|
||||
private System.Windows.Forms.ToolStripButton btnDrawRegion;
|
||||
private System.Windows.Forms.ToolStripButton btnSelectColor;
|
||||
private System.Windows.Forms.ToolStripButton btnDeleteRegion;
|
||||
private System.Windows.Forms.ToolStripButton btnDrawTempDiff;
|
||||
private System.Windows.Forms.ToolStrip tempDiffToolStrip;
|
||||
}
|
||||
}
|
||||
@@ -49,10 +49,6 @@ namespace JoyD.Windows.CS
|
||||
private bool _isMoving = false;
|
||||
private Point _startMovePoint;
|
||||
|
||||
// 工具条拖动相关变量
|
||||
private ToolStrip _draggedToolStrip = null;
|
||||
private Point _dragStartPoint;
|
||||
|
||||
public Setting()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -78,59 +74,6 @@ namespace JoyD.Windows.CS
|
||||
{
|
||||
Console.WriteLine("删除按钮初始化失败: " + ex.Message);
|
||||
}
|
||||
|
||||
// 为工具条添加拖动事件
|
||||
toolStrip.MouseDown += ToolStrip_MouseDown;
|
||||
tempDiffToolStrip.MouseDown += ToolStrip_MouseDown;
|
||||
toolStripContainer.ContentPanel.MouseMove += ContentPanel_MouseMove;
|
||||
toolStripContainer.ContentPanel.MouseUp += ContentPanel_MouseUp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 工具条鼠标按下事件 - 开始拖动
|
||||
/// </summary>
|
||||
private void ToolStrip_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
// 确保点击的是工具条的空白区域或标题栏
|
||||
if (e.Button == MouseButtons.Left && (e.X < toolStrip.PreferredSize.Width && e.Y < 25))
|
||||
{
|
||||
_draggedToolStrip = sender as ToolStrip;
|
||||
_dragStartPoint = e.Location;
|
||||
_draggedToolStrip.Cursor = Cursors.SizeAll;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内容面板鼠标移动事件 - 处理拖动
|
||||
/// </summary>
|
||||
private void ContentPanel_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (_draggedToolStrip != null)
|
||||
{
|
||||
// 计算新位置
|
||||
Point newLocation = toolStripContainer.ContentPanel.PointToClient(_draggedToolStrip.PointToScreen(e.Location));
|
||||
newLocation.X -= _dragStartPoint.X;
|
||||
newLocation.Y -= _dragStartPoint.Y;
|
||||
|
||||
// 确保位置在有效范围内
|
||||
newLocation.X = Math.Max(0, Math.Min(newLocation.X, toolStripContainer.ContentPanel.Width - _draggedToolStrip.Width));
|
||||
newLocation.Y = Math.Max(0, Math.Min(newLocation.Y, toolStripContainer.ContentPanel.Height - _draggedToolStrip.Height));
|
||||
|
||||
// 设置新位置
|
||||
_draggedToolStrip.Location = newLocation;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内容面板鼠标释放事件 - 结束拖动
|
||||
/// </summary>
|
||||
private void ContentPanel_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (_draggedToolStrip != null)
|
||||
{
|
||||
_draggedToolStrip.Cursor = Cursors.Default;
|
||||
_draggedToolStrip = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -118,6 +118,9 @@
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="toolStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
<value>516, 17</value>
|
||||
</metadata>
|
||||
<metadata name="tempDiffToolStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>327, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
Reference in New Issue
Block a user