• c# propertyGrid下拉选项


    实现下面效果的propertygrid属性下拉选择

    具体代码如下

    //form窗口类

        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                properties ps = new properties();
                propertyGrid1.SelectedObject = ps;
            }
        }

    //属性类

        public class properties
        {
            [Category("性别"),Description("student gender"),
            TypeConverter(typeof(genderItem)) //使用自定义的属性下拉item类
            ]
            public string Gender
            {
                get;
                set;
            }
        }

    //自定义属性下拉效果的类,该类主要继承StringConverter类,并重载该类的一些虚拟方法

        public class genderItem:StringConverter
        {
            //true enable,false disable
            public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
            {
                return true;
            }

            public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
            {
                return new StandardValuesCollection(new string[] { "男", "女" }); //编辑下拉框中的items
            }

            //true: disable text editting.    false: enable text editting;
            public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
            {
                return true;
            }
        }

    //形成checkbox选项样式

    属性类的代码如下

            [Category("信息"), Description("student information"),
            Editor(typeof(CheckboxPro),typeof(System.Drawing.Design.UITypeEditor))]
            public bool IsGoodStudent
            {
                get;
                set;
            }

    其中checkboxpro类定义如下,用该方法会出了checkbox窗口

        public class CheckboxPro:System.Drawing.Design.UITypeEditor
        {
            public override bool GetPaintValueSupported(ITypeDescriptorContext context)
            {
                return true;
            }

            public override void PaintValue(System.Drawing.Design.PaintValueEventArgs e)
            {
                ControlPaint.DrawCheckBox(e.Graphics, e.Bounds, ButtonState.Inactive);
            }
        }

  • 相关阅读:
    Java第9次作业--接口及接口回调
    Java第8次作业--继承
    软件工程第三次作业——关于软件质量保障初探
    Java第7次作业--访问权限、对象使用
    Java第6次作业--static关键字、对象
    Java第5次作业--对象的创建与使用
    20194629 自动生成四则运算题第一版报告
    软件工程第一次作业
    今天开通博客啦!
    1170. Compare Strings by Frequency of the Smallest Character
  • 原文地址:https://www.cnblogs.com/tianmochou/p/5085898.html
Copyright © 2020-2023  润新知