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        }
  • 相关阅读:
    MyBatis mapper.xml中SQL处理小于号与大于号 和小于等于号
    iOS打包时Export的四个选择是什么意思?
    Xcode中New Build System和 Legacy build system的区别
    Xcode中Debug、Profile、Release的区别
    versionCode和versionName区别
    Android Studio 3.5 plugin中找不到Flutter插件
    Javascript 面向对象编程(一):封装
    Flutter-常用第三方库
    iOS info.plist 中的隐私权限
    Flutter打包ios应用流程详解
  • 原文地址:https://www.cnblogs.com/3echo/p/883169.html
Copyright © 2011-2022 走看看