c#新手笔记之颜色下拉框
来源:互联网 发布:工程预算软件破解版 编辑:程序博客网 时间:2024/05/17 22:25
颜色填充下拉框
代码:
using System.Reflection;
private void FillColorToCmb(ComboBox cmb)
...{
cmb.DrawMode = DrawMode.OwnerDrawFixed;
cmb.DropDownStyle = ComboBoxStyle.DropDownList;
cmb.DrawItem +=new DrawItemEventHandler(cmb_DrawItem);
cmb.ItemHeight = 18;
cmb.BeginUpdate();
cmb.Items.Clear();
foreach(PropertyInfo pi in typeof(Color).GetProperties(BindingFlags.Public|BindingFlags.Static))
...{
cmb.Items.Add(pi.Name);
}
cmb.EndUpdate();
}
void cmb_DrawItem(object sender, DrawItemEventArgs e)
...{
if(e.Index<0)
return;
e.DrawBackground();
Rectangle rect = new Rectangle(4, e.Bounds.Top + 2, e.Bounds.Height+10, e.Bounds.Height - 4);
ComboBox cmb = (ComboBox)sender;
string colorName = cmb.Items[e.Index].ToString();
SolidBrush b = new SolidBrush(Color.FromName(colorName));
e.Graphics.FillRectangle(b, rect);
e.Graphics.DrawRectangle(Pens.Black, rect);
Font myFont = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular);
e.Graphics.DrawString(colorName, myFont, Brushes.Black,
new RectangleF(e.Bounds.X + rect.Width + 4, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
e.DrawFocusRectangle();
}
private void FillColorToCmb(ComboBox cmb)
...{
cmb.DrawMode = DrawMode.OwnerDrawFixed;
cmb.DropDownStyle = ComboBoxStyle.DropDownList;
cmb.DrawItem +=new DrawItemEventHandler(cmb_DrawItem);
cmb.ItemHeight = 18;
cmb.BeginUpdate();
cmb.Items.Clear();
foreach(PropertyInfo pi in typeof(Color).GetProperties(BindingFlags.Public|BindingFlags.Static))
...{
cmb.Items.Add(pi.Name);
}
cmb.EndUpdate();
}
void cmb_DrawItem(object sender, DrawItemEventArgs e)
...{
if(e.Index<0)
return;
e.DrawBackground();
Rectangle rect = new Rectangle(4, e.Bounds.Top + 2, e.Bounds.Height+10, e.Bounds.Height - 4);
ComboBox cmb = (ComboBox)sender;
string colorName = cmb.Items[e.Index].ToString();
SolidBrush b = new SolidBrush(Color.FromName(colorName));
e.Graphics.FillRectangle(b, rect);
e.Graphics.DrawRectangle(Pens.Black, rect);
Font myFont = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular);
e.Graphics.DrawString(colorName, myFont, Brushes.Black,
new RectangleF(e.Bounds.X + rect.Width + 4, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
e.DrawFocusRectangle();
}
- c#新手笔记之颜色下拉框
- c#下拉颜色框
- C# 实现颜色下拉列表框
- C# 下拉渐变颜色条
- C#实现WORD颜色下拉框控件全过程
- 新手菜鸟学习C#的笔记总结 之委托
- 新手菜鸟学习C#的笔记总结 之接口
- 新手菜鸟学习C#的笔记总结 之事件
- 新手菜鸟学习C#的笔记总结 之泛型
- C#之绝对新手
- 颜色下拉框
- 设置颜色下拉框
- 新手笔记之print(?)
- C#学习笔记之字体窗口和颜色窗口
- combobox 添加颜色下拉框
- QComboBox下拉框 + 颜色相关
- 翻译:C#创建多颜色下拉列表框(Multi-color DropDownList using C#)
- C#创建多颜色下拉列表框 VS.net2003 VS.net2005
- Server2003 DNS服务配置篇
- 在.net使用代理浏览网页
- 有点空,随便写写
- ORACLE 检测回滚段争用,表空间I/O比例
- 找回Windows XP的隐藏选项
- c#新手笔记之颜色下拉框
- 按ctrl+enter提交表单源码
- CVSNT在Windows下的安装和使用
- 如何让复合控件的子控件获得设计时支持
- 人的一生希望能遇上的四个人
- JAVASCRIPT实用的一些技巧
- DropDownList的数据源是Web.Config
- 某个程序安装已在安装计算机上创建挂起的文件操作 错误
- WeiRuan DaBing