C# 自定义控件,怎么加上选中时的效果 类似于按钮选中时颜色会变化 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 自定义什么了?lable textbox gridview combobox? 自定义了一个控件,控件里面包含Panel PictureBox,label private Color pictureBoxBorderColor = Color.Black; private void pictureBox1_Paint(object sender, PaintEventArgs e) { ControlPaint.DrawBorder(e.Graphics, this.pictureBox1.ClientRectangle, pictureBoxBorderColor, 1, ButtonBorderStyle.Solid, pictureBoxBorderColor, 1, ButtonBorderStyle.Solid, pictureBoxBorderColor, 1, ButtonBorderStyle.Solid, pictureBoxBorderColor, 1, ButtonBorderStyle.Solid); } private void pictureBox1_Click(object sender, EventArgs e) { if (pictureBoxBorderColor == Color.Black) { pictureBoxBorderColor = Color.Red; } else { pictureBoxBorderColor = Color.Black; } pictureBox1.Invalidate(); pictureBox1.Update(); } panel中多个picturebox 红边框代表选中 黑边框代表未选中private void Init() { foreach (var item in panel1.Controls) { if(item.GetType()==typeof(PictureBox)) { PictureBox picture = (PictureBox)item; picture.Paint += new PaintEventHandler(picturePaint); picture.Click += new EventHandler(pictureClick); pictureColorDic.Add(picture, Color.Black); } } } private Dictionary<PictureBox, Color> pictureColorDic = new Dictionary<PictureBox, Color>(); void picturePaint(object sender, PaintEventArgs e) { var pictureControl = (sender as PictureBox); var color = pictureColorDic.FirstOrDefault(a => a.Key == pictureControl).Value; if (color == null) { return; } ControlPaint.DrawBorder(e.Graphics, pictureControl.ClientRectangle, color, 1, ButtonBorderStyle.Solid, color, 1, ButtonBorderStyle.Solid, color, 1, ButtonBorderStyle.Solid, color, 1, ButtonBorderStyle.Solid); } void pictureClick(object sender, EventArgs e) { var pictureControl = (sender as PictureBox); var dic = pictureColorDic.FirstOrDefault(a => a.Key == pictureControl); if (dic.Key != null) { pictureColorDic.Remove(pictureControl); if (dic.Value == Color.Black) { pictureColorDic.Add(pictureControl, Color.Red); } else { pictureColorDic.Add(pictureControl, Color.Black); } } pictureControl.Invalidate(); pictureControl.Update(); } datagridView 窗体布局 groupbox控件如何设置与窗体四边的距离? Linq数据库访问类 做一个IIS这样的东西,可以浏览ASP/ASPX网站。怎么做的? 爽,SAP资料下载, datagridview 行到达不可见区域 怎么进行判断啊 读取数据问题 求和和合并 winforms中窗体关闭问题 随机数的代码怎么写。 c#如何嵌入桌面并且按钮可以点击,无边框窗口 我想请教个问题
private Color pictureBoxBorderColor = Color.Black; private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
ControlPaint.DrawBorder(e.Graphics,
this.pictureBox1.ClientRectangle,
pictureBoxBorderColor, 1, ButtonBorderStyle.Solid,
pictureBoxBorderColor, 1, ButtonBorderStyle.Solid,
pictureBoxBorderColor, 1, ButtonBorderStyle.Solid,
pictureBoxBorderColor, 1, ButtonBorderStyle.Solid);
} private void pictureBox1_Click(object sender, EventArgs e)
{
if (pictureBoxBorderColor == Color.Black)
{
pictureBoxBorderColor = Color.Red;
}
else
{
pictureBoxBorderColor = Color.Black;
}
pictureBox1.Invalidate();
pictureBox1.Update();
}
{
foreach (var item in panel1.Controls)
{
if(item.GetType()==typeof(PictureBox))
{
PictureBox picture = (PictureBox)item;
picture.Paint += new PaintEventHandler(picturePaint);
picture.Click += new EventHandler(pictureClick); pictureColorDic.Add(picture, Color.Black);
}
}
} private Dictionary<PictureBox, Color> pictureColorDic = new Dictionary<PictureBox, Color>(); void picturePaint(object sender, PaintEventArgs e)
{
var pictureControl = (sender as PictureBox); var color = pictureColorDic.FirstOrDefault(a => a.Key == pictureControl).Value;
if (color == null) { return; } ControlPaint.DrawBorder(e.Graphics, pictureControl.ClientRectangle,
color, 1, ButtonBorderStyle.Solid,
color, 1, ButtonBorderStyle.Solid,
color, 1, ButtonBorderStyle.Solid,
color, 1, ButtonBorderStyle.Solid); } void pictureClick(object sender, EventArgs e)
{
var pictureControl = (sender as PictureBox); var dic = pictureColorDic.FirstOrDefault(a => a.Key == pictureControl);
if (dic.Key != null)
{
pictureColorDic.Remove(pictureControl);
if (dic.Value == Color.Black)
{
pictureColorDic.Add(pictureControl, Color.Red);
}
else
{
pictureColorDic.Add(pictureControl, Color.Black);
}
}
pictureControl.Invalidate();
pictureControl.Update();
}