• 大小: 93KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-01
  • 语言: C#
  • 标签: C#  ListView  ComboBox  控件  

资源简介

C# ListView中添加ComboBox等控件 效果见 http://blog.csdn.net/xuegacl/article/details/49795479

资源截图

代码片段和文件信息

using System;
using System.Windows.Forms;
using System.Drawing;
using System.Collections;

namespace test
{
    public partial class EXComboBox : ComboBox
    {
        private Brush _highlightbrush; //color of highlighted items

        public EXComboBox()
        {
            _highlightbrush = SystemBrushes.Highlight;
            this.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;
            this.DrawItem += new DrawItemEventHandler(this_DrawItem);
        }

        public Brush MyHighlightBrush
        {
            get { return _highlightbrush; }
            set { _highlightbrush = value; }
        }

        private void this_DrawItem(object sender DrawItemEventArgs e)
        {
            if (e.Index == -1) return;
            e.DrawBackground();
            if ((e.State & DrawItemState.Selected) != 0)
            {
                e.Graphics.FillRectangle(_highlightbrush e.Bounds);
            }
            EXItem item = (EXItem)this.Items[e.Index];
            Rectangle bounds = e.Bounds;
            int x = bounds.X + 2;
            if (item.GetType() == typeof(EXImageItem))
            {
                EXImageItem imgitem = (EXImageItem)item;
                if (imgitem.MyImage != null)
                {
                    Image img = imgitem.MyImage;
                    int y = bounds.Y + ((int)(bounds.Height / 2)) - ((int)(img.Height / 2)) + 1;
                    e.Graphics.DrawImage(img x y img.Width img.Height);
                    x += img.Width + 2;
                }
            }
            else if (item.GetType() == typeof(EXMultipleImagesItem))
            {
                EXMultipleImagesItem imgitem = (EXMultipleImagesItem)item;
                if (imgitem.MyImages != null)
                {
                    for (int i = 0; i < imgitem.MyImages.Count; i++)
                    {
                        Image img = (Image)imgitem.MyImages[i];
                        int y = bounds.Y + ((int)(bounds.Height / 2)) - ((int)(img.Height / 2)) + 1;
                        e.Graphics.DrawImage(img x y img.Width img.Height);
                        x += img.Width + 2;
                    }
                }
            }
            int fonty = bounds.Y + ((int)(bounds.Height / 2)) - ((int)(e.Font.Height / 2));
            e.Graphics.DrawString(item.Text e.Font new SolidBrush(e.ForeColor) x fonty);
            e.DrawFocusRectangle();
        }

        public class EXItem
        {

            private string _text = ““;
            private string _value = ““;

            public EXItem()
            {

            }

            public EXItem(string text)
            {
                _text = text;
            }

            public string Text
            {
                get { return _text; }
                set { _text = value; }
            }

            public string MyValue
            {
               

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-11-12 10:13  test\
     文件         854  2015-11-12 10:08  test.sln
     文件       20480  2015-11-12 10:27  test.suo
     目录           0  2015-11-12 10:10  test\bin\
     目录           0  2015-11-12 10:15  test\bin\Debug\
     文件       28160  2015-11-12 10:39  test\bin\Debug\test.exe
     文件       89600  2015-11-12 10:39  test\bin\Debug\test.pdb
     文件       11600  2015-11-12 10:45  test\bin\Debug\test.vshost.exe
     目录           0  2015-11-12 10:10  test\bin\Release\
     文件        5470  2015-11-12 10:11  test\EXComboBox.cs
     文件       35259  2015-11-12 10:13  test\EXListView.cs
     文件        4183  2015-11-12 10:39  test\Form1.cs
     文件        3337  2015-11-12 10:27  test\Form1.Designer.cs
     文件        6017  2015-11-12 10:27  test\Form1.resx
     目录           0  2015-11-12 10:08  test\obj\
     目录           0  2015-11-12 10:08  test\obj\x86\
     目录           0  2015-11-12 10:39  test\obj\x86\Debug\
     文件        9054  2015-11-12 10:39  test\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6263  2015-11-12 10:39  test\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     目录           0  2015-11-12 10:08  test\obj\x86\Debug\TempPE\
     文件         400  2015-11-12 10:45  test\obj\x86\Debug\test.csproj.FileListAbsolute.txt
     文件         975  2015-11-12 10:35  test\obj\x86\Debug\test.csproj.GenerateResource.Cache
     文件       28160  2015-11-12 10:39  test\obj\x86\Debug\test.exe
     文件         180  2015-11-12 10:35  test\obj\x86\Debug\test.Form1.resources
     文件       89600  2015-11-12 10:39  test\obj\x86\Debug\test.pdb
     文件         180  2015-11-12 10:15  test\obj\x86\Debug\test.Properties.Resources.resources
     文件         485  2015-11-12 10:08  test\Program.cs
     目录           0  2015-11-12 10:08  test\Properties\
     文件        1358  2015-11-12 10:08  test\Properties\AssemblyInfo.cs
     文件        2860  2015-11-12 10:08  test\Properties\Resources.Designer.cs
     文件        5612  2015-11-12 10:08  test\Properties\Resources.resx
............此处省略3个文件信息

评论

共有 条评论