zoukankan      html  css  js  c++  java
  • 定制C# combobox的下拉框

    今天做了个小东西,需要定制combobox的下拉框,打开下拉框时如下图。


    选择一个后,如下图。

    实现的方法是需要把combobox的DrawoMode设置成OwnerDrawVariable,然后处理DrawItem事件,详见ComboBox.DrawItem Event (System.Windows.Forms)代码如下:

        1         private void cb_Risk_DrawItem(object sender, DrawItemEventArgs e)

        2         {

        3             if (e.Index < 0) return;

        4 

        5             switch (e.Index)

        6             {

        7                 case 0:

        8                     e.Graphics.FillRectangle(Brushes.Red, e.Bounds);

        9                     break;

       10                 case 1:

       11                     e.Graphics.FillRectangle(Brushes.Yellow, e.Bounds);

       12                     break;

       13                 case 2:

       14                     e.Graphics.FillRectangle(Brushes.Blue, e.Bounds);

       15                     break;

       16                 default:

       17                     break;

       18             }

       19             e.Graphics.DrawString(cb_Risk.Items[e.Index].ToString(), cb_Risk.Font, Brushes.Black, (RectangleF)e.Bounds);

       20         }


    对了,我这里的代码都是用CopySourceAsHtml这个VS的addin粘进来的,对于VS2010,这篇文章CopyAsHtml in Visual Studio 2010 - AppliSec有一个workaround。



  • 相关阅读:
    大数运算(涉及到格式问题)
    UltraEdit
    汉化eclipse3.6.2
    安装Microsoft SQL Server Management Studio Express是报错29506
    Java相对路径/绝对路径
    恢复Unbuntu的启动项
    UNC路径
    make: g++:命令未找到
    找到个学习html的网站
    HDU 3756 三分
  • 原文地址:https://www.cnblogs.com/fresky/p/1872166.html
Copyright © 2011-2022 走看看