首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

关于DataGridView自定义控件列的有关问题

2013-11-20 
关于DataGridView自定义控件列的问题请教个问题,现有自定义progressbar控件一枚,想在Datagridview中自定义

关于DataGridView自定义控件列的问题
请教个问题,现有自定义progressbar控件一枚,想在Datagridview中自定义一Dridprogress列,就是那一列全为自定义的progressbar控件,无从下手,求各位谁知道的指点下火知道哪有相关问题的发下链接附带自定义的空间代码,也是在CSDN找到的

using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
using System.ComponentModel.Design;
using System.Windows.Forms.Design;

namespace CSUST.Data
{
    [ToolboxItem(true)]
    [ToolboxBitmap(typeof(System.Windows.Forms.ProgressBar))]
    [Designer(typeof(TSmartProgressBarDesinger),typeof(IDesigner))]
    public class TSmartProgressBar : Label
    { 
        private const int m_MaxBarWidth = 20;
        private const int m_MaxBarSpace = 10;

        private int m_Value = 0;
        private int m_Maximum = 100;

        private int m_ProgressBarBlockWidth = 6;
        private int m_ProgressBarBlockSpace = 1;
        private bool m_ProgressBarPercent = true;
        private bool m_ProgressBarMarginOffset = true;

        private TProgressBarBorderStyle m_ProgressBarBorderStyle = TProgressBarBorderStyle.Flat;
        private SolidBrush m_ProgressBarFillBrush;

        public TSmartProgressBar()
        {
            m_ProgressBarFillBrush = new SolidBrush(Color.Coral);

            base.BackColor = Color.White;
            base.ForeColor = Color.Blue;

            base.AutoSize = false;  // AutoSize is Designer Attribute
            base.TextAlign = ContentAlignment.MiddleCenter;   // TextAlign is Designer Attribute
        }

        protected override void Dispose(bool disposing)
        {
            try
            {
                if (disposing)
                {
                    // release managed resource
                }
                m_ProgressBarFillBrush.Dispose();  // release unmanaged resource
            }
            finally
            {
                base.Dispose(disposing);
            }
        }

        #region  custom or modified properties

        [Category("Custom")]
        [Description("Set/Get progress bar fill color.")]
        [DefaultValue(typeof(Color), "Coral")]
        public Color ProgressBarFillColor
        {
            get
            {
                return m_ProgressBarFillBrush.Color;
            }

            set
            {
                if (m_ProgressBarFillBrush.Color != value)
                {
                    m_ProgressBarFillBrush.Color = value;
                    this.Invalidate();


                }
            }
        }

        [Category("Custom")]
        [Description("Set/Get progress small bar width.")]
        [DefaultValue(6)]
        public int ProgressBarBlockWidth
        {
            get { return m_ProgressBarBlockWidth; }
            set
            {
                if (m_ProgressBarBlockWidth != value)
                {
                    if (value < 1)
                    {
                        m_ProgressBarBlockWidth = 1;
                    }
                    else if (value > m_MaxBarWidth)
                    {
                        m_ProgressBarBlockWidth = m_MaxBarWidth;
                    }
                    else
                    {
                        m_ProgressBarBlockWidth = value;
                    }
                    this.Invalidate();
                }
            }
        }

        [Category("Custom")]
        [Description("Set/Get progress bar space width(smooth when 0).")]
        [DefaultValue(1)]
        public int ProgressBarBlockSpace
        {
            get { return m_ProgressBarBlockSpace; }
            set
            {
                if (m_ProgressBarBlockSpace != value)
                {
                    if (value < 0)
                    {
                        m_ProgressBarBlockSpace = 0;
                    }
                    else if (value > m_MaxBarSpace)
                    {
                        m_ProgressBarBlockSpace = m_MaxBarSpace;
                    }
                    else
                    {
                        m_ProgressBarBlockSpace = value;


                    }
                    this.Invalidate();
                }
            }
        }

        [Category("Custom")]
        [Description("Set/Get progress bar boder style.")]
        [DefaultValue(typeof(TProgressBarBorderStyle), "Flat")]
        public TProgressBarBorderStyle ProgressBarBoderStyle
        {
            get { return m_ProgressBarBorderStyle; }
            set
            {
                if (m_ProgressBarBorderStyle != value)
                {
                    m_ProgressBarBorderStyle = value;
                    this.Invalidate();
                }
            }
        }

        [Category("Custom")]
        [Description("Set/Get show percent text or not.")]
        [DefaultValue(true)]
        public bool ProgressBarPercent
        {
            get { return m_ProgressBarPercent; }
            set
            {
                if (m_ProgressBarPercent != value)
                {
                    m_ProgressBarPercent = value;
                    this.Invalidate();
                }
            }
        }

        [Category("Custom")]
        [Description("Set/Get if progress bar has margin offset.")]
        [DefaultValue(true)]
        public bool ProgressBarMarginOffset
        {
            get { return m_ProgressBarMarginOffset; }
            set
            {
                if (m_ProgressBarMarginOffset != value)
                {
                    m_ProgressBarMarginOffset = value;
                    this.Invalidate();
                }
            }
        }

        [Category("Custom")]
        [Description("Set/Get progress bar background color.")]
        [DefaultValue(typeof(Color), "White")]
        public new Color BackColor
        {
            get { return base.BackColor; }
            set
            {
                if(base.BackColor != value)
                {


                    base.BackColor = value;
                    this.Invalidate();
                }
            }
        }

        [Category("Custom")]
        [Description("Set/Get progress bar text color.")]
        [DefaultValue(typeof(Color), "Blue")]
        public new Color ForeColor
        {
            get { return base.ForeColor; }
            set
            {
                if (base.ForeColor != value)
                {
                    base.ForeColor = value;
                    this.Invalidate();
                }
            }
        }

        [Category("Custom")]
        [Description("Set/Get progress bar maximum value.")]
        [DefaultValue(100)]
        public int Maximum
        {
            get { return m_Maximum; }
            set
            {
                if (m_Maximum != value)
                {
                    if (value < 1)
                    {
                        m_Maximum = 1;
                    }
                    else
                    {
                        m_Maximum = value;
                    }
                    if (m_Maximum < m_Value)
                    {
                        m_Value = m_Maximum;
                    }

                    this.Invalidate();
                }
            }
        }

        [Category("Custom")]
        [Description("Set/Get progress bar current value.")]
        [DefaultValue(0)]
        public int Value
        {
            get { return m_Value; }
            set
            {
                if (value < 0)
                {
                    value = 0;


                }
                else if (value > m_Maximum)
                {
                    m_Value = m_Maximum;
                }
                else
                {
                    m_Value = value;
                }

                this.Invalidate();
                this.Update();
            }
        }

        #endregion

        #region disable base properties

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new bool AutoSize
        {
            get
            {
                return base.AutoSize;
            }
        }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new bool AutoEllipsis
        {
            get { return base.AutoEllipsis; }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new System.Drawing.ContentAlignment TextAlign
        {
            get
            {
                return base.TextAlign;
            }
        }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new bool CausesValidation
        {
            get { return base.CausesValidation; }
        }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new bool AllowDrop
        {
            get { return base.AllowDrop; }
        }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new Padding Padding
        {
            get { return base.Padding; }
        }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new ImeMode ImeMode
        {
            get { return base.ImeMode; }
        }

c#? Datagridview


[解决办法]
http://blog.csdn.net/wang371756299/article/details/6410040
[解决办法]
本帖最后由 guwei4037 于 2013-11-19 21:49:40 编辑

引用:
Quote: 引用:

http://blog.csdn.net/wang371756299/article/details/6410040
不会用啊,这个是运行后然后Datagridview的列属性里多了一个类似txtbox列的自定义控件列么?

你看这个吧,有完整的代码。
http://stackoverflow.com/questions/4646920/populating-a-datagridview-with-text-and-progressbars
http://stackoverflow.com/questions/7290009/progress-bar-for-datagridviewcolumn

热点排行