• 大小: 42KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-16
  • 语言: 其他
  • 标签: combobox  控件  图标  

资源简介

首先在窗体中添加一个comboBox1和一个imageList(本例中带有三个图片) this.comboBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace shishi2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
           comboBox1.DrawMode = DrawMode.OwnerDrawFixed; 
            comboBox1.DropDownstyle = ComboBoxstyle.DropDownList; 
            comboBox1.Items.Add(“小车“); 
            comboBox1.Items.Add(“视频“); 
            comboBox1.Items.Add(“信号灯“); 

        }

        private void comboBox1_DrawItem(object sender DrawItemEventArgs e)
        {
            Graphics g = e.Graphics; 
            Rectangle r = e.Bounds; 
            Size imageSize = imageList1.ImageSize; 
      
            if (e.Index >= 0) 
            { 
                Font fn = new Font(“Tahoma“ 10 Fontstyle.Bold); 
                string s = (string)comboBox1.Items[e.Index]; 
                StringFormat sf = new StringFormat(); 
                sf.Alignment = StringAlignment.Near; 
                if (e.State == (DrawItemState.NoAccelerator | DrawItemState.NoFocusRect)) 
                { 
                    //画条目背景 
                    e.Graphics.FillRectangle(new SolidBrush(Color.Red) r); 
                    //绘制图像 
                    imageList1.Draw(e.Graphics r.Left r.Top e.Index); 
                    //显示字符串 
                    e.Graphics.DrawString(s fn new SolidBrush(Color.Black) r.Left + imageSize.Width r.Top); 
                    //显示取得焦点时的虚线框 
                    e.DrawFocusRectangle(); 
                } 
                else 
                { 
                    e.Graphics.FillRectangle(new SolidBrush(Color.LightBlue) r); 
                    imageList1.Draw(e.Graphics r.Left r.Top e.Index); 
                    e.Graphics.DrawString(s fn new SolidBrush(Color.Black) r.Left + imageSize.Width r.Top); 
                    e.DrawFocusRectangle(); 
                } 
            } 


        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      12800  2010-08-20 09:03  shishi2\shishi2\bin\Debug\shishi2.exe

     文件      19968  2010-08-20 09:03  shishi2\shishi2\bin\Debug\shishi2.pdb

     文件      11600  2010-08-20 09:03  shishi2\shishi2\bin\Debug\shishi2.vshost.exe

     文件        490  2010-03-17 22:39  shishi2\shishi2\bin\Debug\shishi2.vshost.exe.manifest

     文件       2175  2010-08-20 09:03  shishi2\shishi2\Form1.cs

     文件       2858  2010-08-20 09:00  shishi2\shishi2\Form1.Designer.cs

     文件      10007  2010-08-20 09:00  shishi2\shishi2\Form1.resx

     文件       2152  2010-08-20 08:58  shishi2\shishi2\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6163  2010-08-20 09:03  shishi2\shishi2\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        172  2010-08-20 09:00  shishi2\shishi2\obj\x86\Debug\GenerateResource.read.1.tlog

     文件        442  2010-08-20 09:00  shishi2\shishi2\obj\x86\Debug\GenerateResource.write.1.tlog

     文件        526  2010-08-20 09:03  shishi2\shishi2\obj\x86\Debug\shishi2.csproj.FileListAbsolute.txt

     文件      12800  2010-08-20 09:03  shishi2\shishi2\obj\x86\Debug\shishi2.exe

     文件       2937  2010-08-20 09:00  shishi2\shishi2\obj\x86\Debug\shishi2.Form1.resources

     文件      19968  2010-08-20 09:03  shishi2\shishi2\obj\x86\Debug\shishi2.pdb

     文件        180  2010-08-20 09:00  shishi2\shishi2\obj\x86\Debug\shishi2.Properties.Resources.resources

     文件        488  2010-08-20 08:58  shishi2\shishi2\Program.cs

     文件       1346  2010-08-20 08:58  shishi2\shishi2\Properties\AssemblyInfo.cs

     文件       2862  2010-08-20 08:58  shishi2\shishi2\Properties\Resources.Designer.cs

     文件       5612  2010-08-20 08:58  shishi2\shishi2\Properties\Resources.resx

     文件       1090  2010-08-20 08:58  shishi2\shishi2\Properties\Settings.Designer.cs

     文件        249  2010-08-20 08:58  shishi2\shishi2\Properties\Settings.settings

     文件       3673  2010-08-20 09:00  shishi2\shishi2\shishi2.csproj

     文件        863  2010-08-20 08:58  shishi2\shishi2.sln

    ..A..H.     17920  2010-08-20 09:14  shishi2\shishi2.suo

     目录          0  2010-08-20 08:58  shishi2\shishi2\obj\x86\Debug\TempPE

     目录          0  2010-08-20 09:03  shishi2\shishi2\obj\x86\Debug

     目录          0  2010-08-20 09:03  shishi2\shishi2\bin\Debug

     目录          0  2010-08-20 08:58  shishi2\shishi2\obj\x86

     目录          0  2010-08-20 08:58  shishi2\shishi2\bin

............此处省略7个文件信息

评论

共有 条评论