加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ColorTracker.cs 3.27 KB
一键复制 编辑 原始数据 按行查看 历史
Magician 提交于 2018-06-20 14:52 . 添加项目文件。
using System;
using System.Drawing;
using System.Windows.Forms;
namespace ColorPane
{
public partial class ColorTracker : UserControl
{
private bool _foreColorizing = true;
public ColorTracker()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
txtR.Left++;
txtG.Left++;
txtB.Left++;
txtR.Left--;
txtG.Left--;
txtB.Left--;
ForeColorizing = _foreColorizing;
}
private void SyncColors(ColorSlider cs)
{
foreach (Control c in Controls)
{
if (c is ColorSlider)
{
if (c != cs) ((ColorSlider)c).RGB = cs.RGB;
}
}
txtR.Text = cs.RGB.R.ToString();
txtG.Text = cs.RGB.G.ToString();
txtB.Text = cs.RGB.B.ToString();
if (_foreColorizing) lblForeColor.BackColor = cs.RGB;
else lblBackColor.BackColor = cs.RGB;
}
[System.ComponentModel.Description("true��ʾ����ǰ��ɫ������Ϊfalse��")]
public bool ForeColorizing
{
get { return _foreColorizing; }
set
{
_foreColorizing = value;
if (_foreColorizing)
{
csR.RGB = lblForeColor.BackColor;
}
else
{
csR.RGB = lblBackColor.BackColor;
}
SyncColors(csR);
}
}
[System.ComponentModel.Description("ѡ���ǰ��ɫ��")]
public Color ForeColorSelection
{
get { return lblForeColor.BackColor; }
set
{
lblForeColor.BackColor = value;
csR.RGB = value;
_foreColorizing = true;
SyncColors(csR);
}
}
[System.ComponentModel.Description("ѡ��ı���ɫ��")]
public Color BackColorSelection
{
get { return lblBackColor.BackColor; }
set
{
lblBackColor.BackColor = value;
csR.RGB = value;
_foreColorizing = false;
SyncColors(csR);
}
}
private void SliderScroll(object sender, SliderEventArgs e)
{
SyncColors((ColorSlider)sender);
}
private void lblForeColor_Click(object sender, EventArgs e)
{
ForeColorizing = true;
}
private void lblBackColor_Click(object sender, EventArgs e)
{
ForeColorizing = false;
}
private void lblSwitch_Click(object sender, EventArgs e)
{
Color temp = lblForeColor.BackColor;
lblForeColor.BackColor = lblBackColor.BackColor;
lblBackColor.BackColor = temp;
ForeColorizing = _foreColorizing;
}
private void lblGray_Click(object sender, EventArgs e)
{
lblBackColor.BackColor = Color.White;
lblForeColor.BackColor = Color.Black;
ForeColorizing = _foreColorizing;
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化