将颜色选择按钮从文本按钮改为图标按钮,显示_selectedColor颜色的矩形
This commit is contained in:
@@ -124,11 +124,12 @@
|
||||
//
|
||||
// btnSelectColor
|
||||
//
|
||||
this.btnSelectColor.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
|
||||
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(75, 22);
|
||||
this.btnSelectColor.Size = new System.Drawing.Size(23, 22);
|
||||
this.btnSelectColor.Text = "选择颜色";
|
||||
this.btnSelectColor.ToolTipText = "选择绘制区域的颜色";
|
||||
this.btnSelectColor.ToolTipText = "选择绘制区域的颜色(点击更换颜色)";
|
||||
//
|
||||
// Setting
|
||||
//
|
||||
|
||||
@@ -201,6 +201,39 @@ namespace JoyD.Windows.CS
|
||||
btnDrawRegion.Image = icon;
|
||||
btnDrawRegion.ImageTransparentColor = Color.Transparent;
|
||||
|
||||
// 设置颜色选择按钮的图标
|
||||
UpdateColorButtonIcon();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新颜色选择按钮的图标,显示_selectedColor颜色的矩形
|
||||
/// </summary>
|
||||
private void UpdateColorButtonIcon()
|
||||
{
|
||||
// 创建颜色选择按钮的图标
|
||||
Bitmap colorIcon = new Bitmap(24, 24);
|
||||
using (Graphics g = Graphics.FromImage(colorIcon))
|
||||
{
|
||||
// 设置高质量绘图
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
|
||||
// 清除背景为透明
|
||||
g.Clear(Color.Transparent);
|
||||
|
||||
// 绘制边框
|
||||
g.DrawRectangle(new Pen(Color.Black, 1), 3, 3, 18, 18);
|
||||
|
||||
// 使用_selectedColor填充矩形
|
||||
using (SolidBrush brush = new SolidBrush(_selectedColor))
|
||||
{
|
||||
g.FillRectangle(brush, 4, 4, 16, 16);
|
||||
}
|
||||
}
|
||||
|
||||
// 设置按钮图标并设置透明色
|
||||
btnSelectColor.Image = colorIcon;
|
||||
btnSelectColor.ImageTransparentColor = Color.Transparent;
|
||||
|
||||
// 启用双缓冲以减少闪烁
|
||||
typeof(PictureBox).InvokeMember("DoubleBuffered",
|
||||
System.Reflection.BindingFlags.SetProperty |
|
||||
@@ -229,11 +262,11 @@ namespace JoyD.Windows.CS
|
||||
// 更新选中的颜色
|
||||
_selectedColor = colorDialog.Color;
|
||||
|
||||
// 更新按钮图标,显示新选择的颜色
|
||||
UpdateColorButtonIcon();
|
||||
|
||||
// 重绘图片区域,显示新颜色的矩形
|
||||
picBoxTemp.Invalidate();
|
||||
|
||||
// 更新按钮文本,显示当前选中的颜色
|
||||
btnSelectColor.Text = string.Format("颜色: {0}", _selectedColor.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user