zoukankan      html  css  js  c++  java
  • 用颜色填充下拉框

     

    用颜色填充下拉框(C#

    代码如下:

     1        private void CtrGifType_Load(object sender, EventArgs e)
     2        {
     3            //透明色初始化设置
     4            cmbTransparence.DrawMode = DrawMode.OwnerDrawFixed;
     5            cmbTransparence.DropDownStyle = ComboBoxStyle.DropDownList;
     6            cmbTransparence.DrawItem += new DrawItemEventHandler(cmbTransparence_DrawItem);
     7            cmbTransparence.ItemHeight = 18;
     8            cmbTransparence.BeginUpdate();
     9            cmbTransparence.Items.Clear();
    10            //循环遍历添加每一项
    11            foreach (PropertyInfo proinfo in typeof(Color).GetProperties(BindingFlags.Public | BindingFlags.Static))
    12            {
    13                cmbTransparence.Items.Add(proinfo.Name);
    14            }

    15            cmbTransparence.EndUpdate();
    16        }

    17
    18        private void cmbTransparence_DrawItem(object sender, DrawItemEventArgs e)
    19        {
    20            if (e.Index < 0return;
    21
    22            e.DrawBackground();
    23
    24            //得到绘制的矩形框
    25            Rectangle rect = new Rectangle(4, e.Bounds.Top + 2, e.Bounds.Height + 10, e.Bounds.Height - 4);
    26
    27            string colorName = cmbTransparence.Items[e.Index].ToString();
    28
    29            //定义单色的画笔
    30            SolidBrush b = new SolidBrush(Color.FromName(colorName));
    31            //内部颜色填充
    32            e.Graphics.FillRectangle(b, rect);
    33            e.Graphics.DrawRectangle(Pens.Black, rect);
    34
    35            //设置显示的字体
    36            Font pFont = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular);
    37
    38            //在指定的矩形内绘制文本
    39            e.Graphics.DrawString(colorName, pFont, Brushes.Black, new Rectangle(e.Bounds.X + rect.Width + 4, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
    40            //在指定的边界范围内绘制聚集框
    41            e.DrawFocusRectangle();
    42        }
  • 相关阅读:
    suse linux 下MYSQL 修改默认字符集
    检查oracle表空间使用情况
    SQL递归查询(SqlServer/ORACLE递归查询)[语法差异分析]
    ORA12519错误解决方案
    全表行转列——动态SQL
    MYSQL 远程连接错误ERROR 2013 (HY000): Lost connection to MySQL server at
    MYSQL根据字段名查询所属表
    ORA12516: TNS: 监听程序找不到符合协议堆栈要求的可用处理程错误解决方案
    suse linux 下取消mysql大小写敏感
    ORACLE根据字段名字查询所属表
  • 原文地址:https://www.cnblogs.com/3echo/p/883169.html
Copyright © 2011-2022 走看看