C# Dev PropertyGrid

本文介绍了如何在C#中使用PropertyGrid控件进行数据绑定,核心是通过反射技术实现。首先展示了如何定义工具类并设置SelectedObject属性,然后提到了如何创建带下拉框的配置,利用TypeConverter实现自定义配置项的转换。最后,文章提及了配置子项列表的方法。
摘要由CSDN通过智能技术生成

使用propertyGridControl控件,在Data工具栏下,核心是利用反射技术

1、定义工具类

添加引用:using System.ComponentModel;

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

namespace XtraVerticalGrid
{
    [DefaultPropertyAttribute("SaveOnClose")]
    public class AppSettings1
    {
        private bool saveOnClose = true;
        private string greetingText = "欢迎使用应用程序!";
        private int maxRepeatRate = 10;
        private int itemsInMRU = 4;
        private bool settingsChanged = false;
        private string appVersion = "1.0";
        private string DefaultFileName = "Name";

        private Size windowSize = new Size(100, 100);
        private Font windowFont = new Font("宋体", 9, FontStyle.Regular);
        private Color toolbarColor = SystemColors.Control;
        [CategoryAttribute("文档设置"),
        DefaultValueAttribute(true)]
        public bool SaveOnClose
        {
            get { return saveOnClose; }
            set { saveOnClose = value; }
        }
        [CategoryAttribute("文档设置")]
        public Size WindowSize
        {
            get { return windowSize; }
            set { windowSize = value; }
        }
        [CategoryAttribute("文档设置")]
        public Font WindowFont
        {
            get { return windowFont; }
            set { windowFont = value; }
        }
        [CategoryAttribute("全局设置")]
        public Color ToolbarColor
        {
            get { return toolbarColor; }
            set { toolbarColor = value; }
        }
        [CategoryAttribute("全局设置"),
        ReadOnlyAttribute(true),
        DefaultValueAttribute("欢迎使用应用程序!")]
        public string GreetingText
        {
            get { return greetingText; }
            set { greetingText = value; }
        }
        [CategoryAttribute("全局设置"),
        DefaultValueAttribute(4)]
        public int ItemsInMRUList
        {
            get { return itemsInMRU; }
            set { itemsInMRU = value; }
        }
        [DescriptionAttribute("以毫秒表示的文本重复率。"),
        CategoryAttribute("全局设置"),
        DefaultValueAttribute(10)]
        public int MaxRepeatRate
        {
            get { return maxRepeatRate; }
            set { maxRepeatRate = value; }
        }
        [BrowsableAttribute(false),
        DefaultValueAttribute(false)]
        public bool SettingsChanged
        {
            get { return settingsChanged; }
            set { settingsChanged = value; }
        }
        [CategoryAttribute("版本"),
        DefaultValueAttribute("1.0"),
        ReadOnlyAttribute(true)]
        public string AppVersion
        {
            get { return appVersion; }
            set { appVersion = value; }
        }
        [CategoryAttribute("拼写检查选项"),
        DefaultValueAttribute("DefaultFileName")]
        public string SpellingO
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值