• 用颜色填充下拉框


     

    用颜色填充下拉框(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        }
  • 相关阅读:
    Mysql技术内幕——InnoDB存储引擎
    Nginx 0.7.x + PHP 5.2.6(FastCGI)+ MySQL 5.1 在128M小内存VPS服务器上的配置优化
    Mysql5.5 InnoDB存储引擎配置和优化
    MySQL存储引擎总结
    MySQL存储引擎--MyISAM与InnoDB区别
    MySQL存储引擎
    Mysql的建表规范与注意事项
    安装好oracle11gR2之后在相应路径下却没有生成tnsnames.ora和listener.ora
    split切割.号的字符串
    配置文件c3p0-config.xml
  • 原文地址:https://www.cnblogs.com/3echo/p/883169.html
Copyright © 2020-2023  润新知