修复画笔大小按钮未初始化的编译警告

This commit is contained in:
zqm
2025-11-10 11:21:52 +08:00
parent 48d3792464
commit 53db7ff081

View File

@@ -40,6 +40,9 @@ namespace JoyD.Windows.CS
this.btnDrawTempDiff = new System.Windows.Forms.ToolStripButton();
this.btnAddTempDiff = new System.Windows.Forms.ToolStripButton();
this.btnDeleteTempDiff = new System.Windows.Forms.ToolStripButton();
this.btnBrushSize1 = new System.Windows.Forms.ToolStripButton();
this.btnBrushSize3 = new System.Windows.Forms.ToolStripButton();
this.btnBrushSize5 = new System.Windows.Forms.ToolStripButton();
((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
this.splitContainer.Panel1.SuspendLayout();
this.splitContainer.Panel2.SuspendLayout();
@@ -127,6 +130,39 @@ namespace JoyD.Windows.CS
this.dataGridViewTempDiff.Size = new System.Drawing.Size(309, 425);
this.dataGridViewTempDiff.TabIndex = 0;
//
// btnBrushSize1
//
this.btnBrushSize1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.btnBrushSize1.Image = this.CreateBrushSizeImage(1, System.Drawing.Color.Red);
this.btnBrushSize1.ImageTransparentColor = System.Drawing.Color.Magenta;
this.btnBrushSize1.Name = "btnBrushSize1";
this.btnBrushSize1.Size = new System.Drawing.Size(23, 22);
this.btnBrushSize1.Text = "画笔大小1px";
this.btnBrushSize1.ToolTipText = "选择1像素画笔";
this.btnBrushSize1.Click += new System.EventHandler(this.BtnBrushSize1_Click);
//
// btnBrushSize3
//
this.btnBrushSize3.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.btnBrushSize3.Image = this.CreateBrushSizeImage(3, System.Drawing.Color.Green);
this.btnBrushSize3.ImageTransparentColor = System.Drawing.Color.Magenta;
this.btnBrushSize3.Name = "btnBrushSize3";
this.btnBrushSize3.Size = new System.Drawing.Size(23, 22);
this.btnBrushSize3.Text = "画笔大小3px";
this.btnBrushSize3.ToolTipText = "选择3像素画笔";
this.btnBrushSize3.Click += new System.EventHandler(this.BtnBrushSize3_Click);
//
// btnBrushSize5
//
this.btnBrushSize5.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.btnBrushSize5.Image = this.CreateBrushSizeImage(5, System.Drawing.Color.Blue);
this.btnBrushSize5.ImageTransparentColor = System.Drawing.Color.Magenta;
this.btnBrushSize5.Name = "btnBrushSize5";
this.btnBrushSize5.Size = new System.Drawing.Size(23, 22);
this.btnBrushSize5.Text = "画笔大小5px";
this.btnBrushSize5.ToolTipText = "选择5像素画笔";
this.btnBrushSize5.Click += new System.EventHandler(this.BtnBrushSize5_Click);
//
// toolStrip
//
this.toolStrip.AllowDrop = true;
@@ -138,7 +174,11 @@ namespace JoyD.Windows.CS
this.btnDeleteRegion,
this.btnDrawTempDiff,
this.btnAddTempDiff,
this.btnDeleteTempDiff});
this.btnDeleteTempDiff,
new System.Windows.Forms.ToolStripSeparator(),
this.btnBrushSize1,
this.btnBrushSize3,
this.btnBrushSize5});
this.toolStrip.Location = new System.Drawing.Point(3, 0);
this.toolStrip.Name = "toolStrip";
this.toolStrip.Size = new System.Drawing.Size(104, 25);
@@ -248,6 +288,33 @@ namespace JoyD.Windows.CS
private System.Windows.Forms.ToolStripButton btnDrawTempDiff;
private System.Windows.Forms.ToolStripButton btnAddTempDiff;
private System.Windows.Forms.ToolStripButton btnDeleteTempDiff;
private System.Windows.Forms.ToolStripButton btnBrushSize1;
private System.Windows.Forms.ToolStripButton btnBrushSize3;
private System.Windows.Forms.ToolStripButton btnBrushSize5;
private System.Windows.Forms.DataGridView dataGridViewTempDiff;
/// <summary>
/// 创建表示画笔大小的图标
/// </summary>
/// <param name="size">画笔大小(像素)</param>
/// <param name="color">画笔颜色</param>
/// <returns>表示画笔大小的图标</returns>
private System.Drawing.Bitmap CreateBrushSizeImage(int size, System.Drawing.Color color)
{
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(20, 20);
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
{
// 填充背景为透明色
g.Clear(System.Drawing.Color.Magenta);
// 计算正方形位置,使其居中
int x = (20 - size) / 2;
int y = (20 - size) / 2;
// 绘制正方形表示画笔大小
g.FillRectangle(new System.Drawing.SolidBrush(color), x, y, size, size);
// 添加边框
g.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.Black), x, y, size - 1, size - 1);
}
return bmp;
}
}
}