源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

c#构造ColorComboBox(颜色下拉框)

  • 时间:2022-08-06 05:47 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:c#构造ColorComboBox(颜色下拉框)
[u]复制代码[/u] 代码如下:
    class ColorComboBox : ComboBox     {         /// <summary>         /// 当前选中色         /// </summary>         public Color SelectedColor         {             get { return Color.FromName(this.Text); }         }         /// <summary>         /// 构造函数,构造颜色下拉列表         /// </summary>         public ColorComboBox()         {             this.DrawMode = DrawMode.OwnerDrawFixed;             this.DropDownStyle = ComboBoxStyle.DropDownList;             this.ItemHeight = 25;             PropertyInfo[] propInfoList = typeof(Color).GetProperties(BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.Public);             foreach (PropertyInfo c in propInfoList)             {                 this.Items.Add(c.Name);             }             this.Text = "Black"; //设置默认色         }         protected override void OnDrawItem(DrawItemEventArgs e)         {             Rectangle rect = e.Bounds;             if (e.Index >= 0)             {                 string colorName = this.Items[e.Index].ToString();                 Color c = Color.FromName(colorName);                 using (Brush b = new SolidBrush(c)) //预留下拉项间距                 {                     e.Graphics.FillRectangle(b, rect.X, rect.Y + 2, rect.Width, rect.Height - 4);                 }             }         }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部