修复btnSelectColor字段未初始化警告,添加颜色选择功能
This commit is contained in:
@@ -28,13 +28,13 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Setting));
|
||||
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.toolStrip = new System.Windows.Forms.ToolStrip();
|
||||
this.btnDrawRegion = new System.Windows.Forms.ToolStripButton();
|
||||
this.btnSelectColor = new System.Windows.Forms.ToolStripButton();
|
||||
((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
|
||||
this.splitContainer.Panel1.SuspendLayout();
|
||||
this.splitContainer.Panel2.SuspendLayout();
|
||||
@@ -103,10 +103,12 @@
|
||||
this.toolStrip.Dock = System.Windows.Forms.DockStyle.None;
|
||||
this.toolStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||
this.toolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.btnDrawRegion});
|
||||
this.btnDrawRegion,
|
||||
this.btnSelectColor});
|
||||
this.toolStrip.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.Flow;
|
||||
this.toolStrip.Location = new System.Drawing.Point(0, 0);
|
||||
this.toolStrip.Name = "toolStrip";
|
||||
this.toolStrip.Size = new System.Drawing.Size(75, 27);
|
||||
this.toolStrip.Size = new System.Drawing.Size(24, 7);
|
||||
this.toolStrip.TabIndex = 1;
|
||||
this.toolStrip.Text = "toolStrip";
|
||||
//
|
||||
@@ -116,10 +118,18 @@
|
||||
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(24, 24);
|
||||
this.btnDrawRegion.Size = new System.Drawing.Size(23, 4);
|
||||
this.btnDrawRegion.Text = "画框";
|
||||
this.btnDrawRegion.ToolTipText = "绘制温度检测区域(点击开启/关闭)";
|
||||
//
|
||||
// btnSelectColor
|
||||
//
|
||||
this.btnSelectColor.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
|
||||
this.btnSelectColor.Name = "btnSelectColor";
|
||||
this.btnSelectColor.Size = new System.Drawing.Size(75, 22);
|
||||
this.btnSelectColor.Text = "选择颜色";
|
||||
this.btnSelectColor.ToolTipText = "选择绘制区域的颜色";
|
||||
//
|
||||
// Setting
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
|
||||
@@ -152,5 +162,6 @@
|
||||
private System.Windows.Forms.ToolStripContainer toolStripContainer;
|
||||
private System.Windows.Forms.ToolStrip toolStrip;
|
||||
private System.Windows.Forms.ToolStripButton btnDrawRegion;
|
||||
private System.Windows.Forms.ToolStripButton btnSelectColor;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@@ -27,6 +27,7 @@ namespace JoyD.Windows.CS
|
||||
private Rectangle _currentRectangle = Rectangle.Empty;
|
||||
private bool _isDrawing = false;
|
||||
private List<Rectangle> _drawnRectangles = new List<Rectangle>();
|
||||
private Color _selectedColor = Color.Red;
|
||||
|
||||
public Setting()
|
||||
{
|
||||
@@ -45,6 +46,7 @@ namespace JoyD.Windows.CS
|
||||
|
||||
// 注册按钮点击事件
|
||||
btnDrawRegion.Click += BtnDrawRegion_Click;
|
||||
btnSelectColor.Click += BtnSelectColor_Click;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -145,7 +147,7 @@ namespace JoyD.Windows.CS
|
||||
// 绘制所有已完成的矩形
|
||||
foreach (Rectangle rect in _drawnRectangles)
|
||||
{
|
||||
e.Graphics.DrawRectangle(new Pen(Color.Red, 2), rect);
|
||||
e.Graphics.DrawRectangle(new Pen(_selectedColor, 2), rect);
|
||||
}
|
||||
|
||||
// 绘制当前正在绘制的矩形
|
||||
@@ -203,9 +205,35 @@ namespace JoyD.Windows.CS
|
||||
System.Reflection.BindingFlags.Instance |
|
||||
System.Reflection.BindingFlags.NonPublic,
|
||||
null, picBoxTemp, new object[] { true });
|
||||
}
|
||||
|
||||
// 注册Paint事件
|
||||
picBoxTemp.Paint += PicBoxTemp_Paint;
|
||||
/// <summary>
|
||||
/// 颜色选择按钮点击事件
|
||||
/// </summary>
|
||||
private void BtnSelectColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
using (ColorDialog colorDialog = new ColorDialog())
|
||||
{
|
||||
// 设置初始颜色为当前选中的颜色
|
||||
colorDialog.Color = _selectedColor;
|
||||
|
||||
// 允许自定义颜色
|
||||
colorDialog.AllowFullOpen = true;
|
||||
colorDialog.FullOpen = true;
|
||||
|
||||
// 显示颜色选择对话框
|
||||
if (colorDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
// 更新选中的颜色
|
||||
_selectedColor = colorDialog.Color;
|
||||
|
||||
// 重绘图片区域,显示新颜色的矩形
|
||||
picBoxTemp.Invalidate();
|
||||
|
||||
// 更新按钮文本,显示当前选中的颜色
|
||||
btnSelectColor.Text = string.Format("颜色: {0}", _selectedColor.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user