• 大小: 20KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-16
  • 语言: C#
  • 标签: C#  ListView  CheckBox  ComboBox  

资源简介

C#的ListView添加各种自定义控件,CheckBox,ComboBox等

资源截图

代码片段和文件信息

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
            {
               

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

     文件       5470  2015-11-12 10:11  C#ListView中添加自定义控件\test\EXComboBox.cs

     文件      35259  2015-11-12 10:13  C#ListView中添加自定义控件\test\EXListView.cs

     文件       4183  2015-11-12 10:39  C#ListView中添加自定义控件\test\Form1.cs

     文件       3337  2015-11-12 10:27  C#ListView中添加自定义控件\test\Form1.Designer.cs

     文件       6017  2015-11-12 10:27  C#ListView中添加自定义控件\test\Form1.resx

     文件        485  2015-11-12 10:08  C#ListView中添加自定义控件\test\Program.cs

     文件       1358  2015-11-12 10:08  C#ListView中添加自定义控件\test\Properties\AssemblyInfo.cs

     文件       2860  2015-11-12 10:08  C#ListView中添加自定义控件\test\Properties\Resources.Designer.cs

     文件       5612  2015-11-12 10:08  C#ListView中添加自定义控件\test\Properties\Resources.resx

     文件       1091  2015-11-12 10:08  C#ListView中添加自定义控件\test\Properties\Settings.Designer.cs

     文件        249  2015-11-12 10:08  C#ListView中添加自定义控件\test\Properties\Settings.settings

     文件       3849  2015-11-12 10:14  C#ListView中添加自定义控件\test\test.csproj

     文件        854  2015-11-12 10:08  C#ListView中添加自定义控件\test.sln

    ..A..H.     20480  2015-11-12 10:27  C#ListView中添加自定义控件\test.suo

     目录          0  2018-01-15 14:39  C#ListView中添加自定义控件\test\bin

     目录          0  2015-11-12 10:08  C#ListView中添加自定义控件\test\Properties

     目录          0  2018-01-15 14:39  C#ListView中添加自定义控件\test

     目录          0  2018-01-15 14:38  C#ListView中添加自定义控件

----------- ---------  ---------- -----  ----

                91104                    18


评论

共有 条评论