zoukankan      html  css  js  c++  java
  • 一个c# ColorListBox

    介绍 在这篇文章中,

      

    我们将看到如何编写所有者绘制列表框 控制。通常,Windows处理绘制要显示的项的任务 列表框。您可以使用DrawMode 属性并处理度量项 和DrawItem 事件提供覆盖该窗口的自动绘制能力 提供并自己画项目。您可以使用所有者绘制的列表框 控件以显示可变高度的项、图像或不同的颜色或字体 浏览列表中每个项目的文本。 描述 我们从创建一个Windows应用程序开始。添加列表框 设置窗体的DrawMode属性为OwnerDrawVariable。 或者,您可以将以下行添加到InitializeComponent 你的形式的功能, 隐藏,复制Code

    //lstColor is ListBox control
    this.lstColor.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;

    下一步添加下列线以下的线以上 隐藏,复制Code

    //tell windows we are interested in drawing items in ListBox on our own
    this.lstColor.DrawItem += new DrawItemEventHandler(this.DrawItemHandler);
    
    //tell windows we are interested in providing  item size
    this.lstColor.MeasureItem += 
      new System.Windows.Forms.MeasureItemEventHandler(this.MeasureItemHandler);

    通过这样做,windows将发送DrawItem和MeasureItem事件给我们 每个项目添加到列表框。 接下来,为这些事件添加处理程序 隐藏,复制Code

    private void DrawItemHandler(object sender, DrawItemEventArgs e)
    {
        e.DrawBackground();
        e.DrawFocusRectangle();
        e.Graphics.DrawString(data[e.Index], 
                              new Font(FontFamily.GenericSansSerif, 
                                       14, FontStyle.Bold),
                              new SolidBrush(color[e.Index]), 
                              e.Bounds);
     
    }
    
    private void MeasureItemHandler(object sender, MeasureItemEventArgs e)
    {
        e.ItemHeight= 22;
    }

    在上面的代码中,date是保存要插入的项的数组,color是 类颜色数组 这是它。我们是做! 请在lparam@hotmail.com上给我留言 本文转载于:http://www.diyabc.com/frontweb/news232.html

  • 相关阅读:
    为什么要使用虚拟内存?
    iptables系列
    MySQL 加锁处理分析
    血战的浏览器历史
    TCP协议详解
    OAuth 2.0详解
    Redis 和 I/O 多路复用
    Kubernetes的十大使用技巧
    Nginx动态路由的新姿势:使用Go取代lua
    个人博客实现Archives查询小记
  • 原文地址:https://www.cnblogs.com/Dincat/p/13431192.html
Copyright © 2011-2022 走看看