C#开发学习笔记:使用PropertyGridControl编写自定义属性

如何让DEV PropertyGridControl根据自定义Attribute特性来自定义输入显示 -------基于Dev13.2.5及以上版本 阅读详情
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DemoCollection
{
    public partial class FormPropertyGridControl : Form
    {
        public FormPropertyGridControl()
        {
            InitializeComponent();
        }

        private void FormPropertyGridControl_Load(object sender, EventArgs e)
        {
            CustomAttribute customAttribute = new CustomAttribute();
            CustomAttribute1 customAttribute1 = new CustomAttribute1();
            CustomAttribute2 customAttribute2 = new CustomAttribute2();

            //实例化一个CustomAttribute1类型的对象,将它赋值给customAttribute的CA1属性
            //这样CA1属性就会展示CustomAttribute1类型对象的属性成员
            customAttribute.CA1 = customAttribute1;
            customAttribute1.CustomDisplayFormart = customAttribute2;

            propertyGridControl1.SelectedObject = customAttribute;//设置要展示属性的对象
            propertyGridControl1.ExpandAllRows();//展开所有属性(包括子属性)
            propertyGridControl1.RowHeaderWidth = 100;//设置自定义属性左边属性名称的宽度

            //设置属性不按A-Z排序
            propertyGridControl1.OptionsBehavior.PropertySort = DevExpress.XtraVerticalGrid.PropertySort.NoSort;

            //设置属性按A-Z排序
            //propertyGridControl1.OptionsBehavior.PropertySort = DevExpress.XtraVerticalGrid.PropertySort.Alphabetical;

            DevExpress.XtraVerticalGrid.Rows.BaseRow br= propertyGridControl1.GetRowByCaption("自定义属性");

            //通过循环遍历设置属性的中文名称
            foreach (DevExpress.XtraVerticalGrid.Rows.PGridEditorRow per in br.ChildRows)
            {
                if (per.ChildRows.Count>0)
                {
                    //利用递归解决多层可扩展属性的caption的赋值
                    SetCustomAttributeCaption(per);
                }
                string dicKey = per.Properties.FieldName;
                if (CustomAttribute.dic.ContainsKey(dicKey))
                    per.Properties.Caption = CustomAttribute.dic[dicKey];
                per.Height = 23;//设置属性行高度
                
            }

            propertyGrid1.SelectedObject = customAttribute;//设置要展示属性的对象
            propertyGrid1.ExpandAllGridItems();//展开所有属性(包括子属性)

            

        }
        /// <summary>
        /// 设置自定义属性的描述
        /// </summary>
        private void SetCustomAttributeCaption(DevExpress.XtraVerticalGrid.Rows.PGridEditorRow PGridEditorRow)
        {
            foreach (DevExpress.XtraVerticalGrid.Rows.PGridEditorRow per_child in PGridEditorRow.ChildRows)
            {
                if (per_child.ChildRows.Count > 0)
                {
                    //利用递归解决多层可扩展属性的caption的赋值
                    SetCustomAttributeCaption(per_child);
                }
                //FieldName属性包含了该属性的父属性FieldName;通过 . 分割
                string[] per_child_FieldName= per_child.Properties.FieldName.Split('.');
                string dicKey = per_child_FieldName[per_child_FieldName.GetLength(0) - 1];
                if (CustomAttribute.dic.ContainsKey(dicKey))
                    per_child.Properties.Caption = CustomAttribute.dic[dicKey];
                per_child.Height = 23;//设置属性行高度
            }
        }
    }
    
    /// <summary>
    /// 自定义属性类
    /// </summary>
    class CustomAttribute
    {
        /// <summary>
        /// 用于存放属性英文-中文的键值对
        /// </summary>
        public static Dictionary<string, string> dic = new Dictionary<string, string>();
        public enum VisibleStatus
        {
            True,
            False
        }

        CustomAttribute1 _ca1;
        private string _CustomName = "";
        private string _CustomNameDesc = "";
        private VisibleStatus _Visible = VisibleStatus.False;
        private Color _CustomColor;
        private DateTime _CustomDateTime;
        private string _CustomDisplayFormart = "";
        private string _CustomFormartString = "";
        public CustomAttribute()
        {
            dic.Add("CustomName", "名称");
            dic.Add("CustomNameDesc", "名称描述");
            dic.Add("CustomVisible", "是否隐藏");
            dic.Add("CustomColor", "颜色");
            dic.Add("CustomDateTime", "时间");
            dic.Add("CA1", "可展开属性"); 
        }
       
        /// <summary>
        /// 名称
        /// </summary>
        [Browsable(true),Category("自定义属性")]        
        public string CustomName
        {
            get { return _CustomName; }
            set 
            { 
                _CustomName = value;
                
            }
        }

        /// <summary>
        /// 名称描述
        /// </summary>
        [Browsable(true), Category("自定义属性")]
        public string CustomNameDesc
        {
            get { return _CustomNameDesc; }
            set 
            { 
                _CustomNameDesc = value; 
                
            }
        }
        /// <summary>
        /// 是否隐藏
        /// </summary>
        [Browsable(true), Category("自定义属性")]
        public VisibleStatus CustomVisible
        {
            get { return _Visible; }
            set 
            { 
                _Visible = value; 
                
            }
        }

        /// <summary>
        /// 颜色
        /// </summary>
        [Browsable(true), Category("自定义属性")]
        public Color CustomColor
        {
            get { return _CustomColor; }
            set 
            { 
                _CustomColor = value;
                
            }
        }
        /// <summary>
        /// 时间
        /// </summary>
        [Browsable(true), Category("自定义属性")]
        public DateTime CustomDateTime
        {
            get { return _CustomDateTime; }
            set 
            { 
                _CustomDateTime = value;
                
            }
        }

        /// <summary>
        /// 可展开属性
        /// </summary>
        /// TypeConverter(typeof(ExpandableObjectConverter)):将CustomAttribute1类型的对象转为可扩展对象
        [Browsable(true), Category("自定义属性"),TypeConverter(typeof(ExpandableObjectConverter))]
        public CustomAttribute1 CA1
        {
            get { return _ca1; }
            set 
            { 
                _ca1 = value;
                
            }
        }
    }

    /// <summary>
    /// 自定义属性类1
    /// </summary>
    class CustomAttribute1
    {
        public CustomAttribute1()
        {
            CustomAttribute.dic.Add("CustomDisplayFormart", "显示类型");
            CustomAttribute.dic.Add("CustomFormartString", "类型格式"); 
        }
        private CustomAttribute2 _CustomDisplayFormart;
        private string _CustomFormartString = "";
        /// <summary>
        /// 显示类型
        /// </summary>
        [Browsable(true), TypeConverter(typeof(ExpandableObjectConverter))]
        public CustomAttribute2 CustomDisplayFormart
        {
            get { return _CustomDisplayFormart; }
            set 
            {
                _CustomDisplayFormart = value;
                
            }
        }
        /// <summary>
        /// 类型格式
        /// </summary>
        public string CustomFormartString
        {
            get { return _CustomFormartString; }
            set 
            { 
                _CustomFormartString = value;
                
            }
        }
    }
    /// <summary>
    /// 自定义属性类2
    /// </summary>
    class CustomAttribute2
    {
        public CustomAttribute2()
        {
            CustomAttribute.dic.Add("CustomDisplayFormartValue", "显示格式值");
            CustomAttribute.dic.Add("AllowUseCustomDisplayFormart", "是否启用显示格式");
        }
        private string _CustomDisplayFormartValue = "";
        private CustomAttribute.VisibleStatus _AllowUseCustomDisplayFormart = CustomAttribute.VisibleStatus.False;
        /// <summary>
        /// 值
        /// </summary>
        public string CustomDisplayFormartValue
        {
            get { return _CustomDisplayFormartValue; }
            set
            {
                _CustomDisplayFormartValue = value;

            }
        }
        /// <summary>
        /// 是否启用
        /// </summary>
        public CustomAttribute.VisibleStatus AllowUseCustomDisplayFormart
        {
            get { return _AllowUseCustomDisplayFormart; }
            set
            {
                _AllowUseCustomDisplayFormart = value;

            }
        }
    }
}

 

wpf devexpress Property Grid创建属性定义 打开工具箱在vs,定位到DX.23.1: Data 面板,选择PropertyGridControl工具箱选项,拖动到窗口。使用property grid PropertyGridControl.SelectedObject 属性绑定数据。本教程示范如何绑定WP Property Grid控件到数据和创建属性定义。WPF Property Grid控件使用属性定义定义如何做和显示。第三步-绑定Property Grid到Data Object。第一步-创建属性定义。步骤四-创建属性定义。 阅读详情

相关推荐

C# winform动态添加属性控件propertyGrid1的项

private void Form1_Load(object sender, EventArgs e)         {             object[] s = new object[] { true, false };             for (int i = 0; i             {                 Property pp = new

sutoncai的专栏 6614

C# PropertyGrid 简单使用

2. 通过Enum.ToString()实现,将String[] 变为 Enum,通过 Enum 实现下拉框。常用属性 PropertyGrid 中已经封装了下拉框属性。1. 通过继承重写 StringConverter 函数。2. 根据字段封装顺序。

Thomas会写字 7757

C# Dev PropertyGrid

使用propertyGridControl控件,在Data工具栏下,核心是利用反射技术 1、定义工具类 添加引用:using System.ComponentModel; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; usi

面朝大海,春暖花开 3722

【学习笔记】PropertyGridControl使用

PropertyGridControl使用 场景一 在项目中,遇到一种情况,当一个属性的值选项不同时,与之相关的属性需要动态设置属性的隐藏或者显示。 /// <summary> /// 实体属性处理 /// </summary> public class PropertyHandle { #region 反射控制只读、可见属性 //SetPropertyVisibility(obj, "名称 ",

qq_38310237的博客 2214

WinForms开发小技巧:用PropertyGrid实现类似Visual Studio的属性面板效果

本文详细介绍了如何在WinForms开发中使用PropertyGrid控件实现类似Visual Studio的专业属性面板效果。通过智能属性折叠控制、视觉增强、高级交互功能以及性能优化等技巧,开发者可以显著提升桌面应用的用户体验和专业度。文章包含大量C#代码示例,特别适合需要定制属性面板的中高级WinForms开发者。

weixin_42525551的博客 155

Dev控件PropertyGridContral使用

Dev控件PropertyGridContral使用20150429

C# Dev控件中的 PropertyGridControl 属性控件的基本用法以及排序

在这个例子中将实现让该属性控件实现排序按钮。 效果如图:   首先2个按钮是 CheckButton 控件。 然后是一个:PropertyGridControl  控件   为了美观一点,将2个CheckButton控件的AllowFocus属性设置为 False ----------------------------------------------------------

8641

C#实现ProperTyGrid自定义属性的方法

主要介绍了C#实现ProperTyGrid自定义属性的方法,主要通过接口ICustomTypeDescriptor实现,需要的朋友可以参考下

Dev PropertyGridControl控件 移除某一Category下的属性

private void propertyGridControl1_CustomPropertyDescriptors(object sender, DevExpress.XtraVerticalGrid.Events.CustomPropertyDescriptorsEventArgs e) { if (e.Context.PropertyDescr...

清风专栏 902

Apache Doris IP变更问题详解

Apache Doris IP变更问题详解

ith321的博客 7274

cartographer从入门到精通(一):cartographer介绍

Cartographer的架构图我们可以看到白色框出来的三个区域,分别是Input Sensor Data(数据输入模块)Local SLAM(局部SLAM模块)Global SLAM (background thread)(全局SLAM模块)下面我们分别介绍一下这几个模块。

weixin_68094467的博客 1052

界面控件DevExpress WPF v24.1新版亮点:属性网格、轻量级主题升级

DevExpress WPF控件今年一个重大版本——v24.1全新发布,此版本全新升级了属性网格、电子表格、轻量级主题等功能,欢迎下载最新版体验!

需要界面开发、IDE工具研发中文教程资料的小伙伴,记得私信我~ 1122

【笔记】2022.6.7 数据分析概论

已完结

SpriteNym的博客 1372

C# propertyGrid控件实现属性折叠的控制

控件时,你可能希望在加载某个对象时只默认展开一个特定的Category,而其他Category保持折叠状态。集合,然后对除了你想要展开的那个Category之外的所有Category设置它们的。本身没有直接提供这样的功能,但是你可以通过一些技巧来达到目的。方法来控制属性的展开和折叠。但是如果只展开某一个特定的分类。如果是全部的折叠和展开,我们可以使用。一种方法是在加载对象到。

精通搬砖,资深技术砖家,在软件开发,人工智能,设备开发等领域都有研究。商业合作&交流学习可私信联系。 987

转换shp坐标系之前,设置转换的投影

1.点击目录》工具箱》系统工具箱》Data Management Tools.tbx》投影和变换》创建自定义地理(坐标)变换 2.名称自定义 2.输入地理坐标系可以根据所需要转换的shp文件属性中查询出来 把图层拖入arcgis中,右键属性即可查看 3.复制坐标系,点击“输入地理坐标系”右侧的按钮后,粘贴在顶部搜索框中,并按enter键,选择对应的坐标系 4.点击“输出地理坐标系”右侧的按钮后,选择转换后的坐标系,如4326,选择后点击确认按钮。 5.自定义方法中选择

Wangwangwang___的博客 1862

Tessent ATPG进阶:解锁多种Fault Model的工程实践与选型指南

本文深入探讨Tessent ATPG中多种Fault Model的工程实践与选型策略,涵盖Stuck-at、Transition、Bridge等核心模型的应用场景与配置技巧。通过实际案例解析,展示如何组合不同Fault Model提升芯片测试覆盖率,特别针对汽车电子、超低功耗芯片等复杂场景提供专业解决方案。

weixin_30219613的博客 198

C# 设计时动态改变实体在PropertyGrid中显示出来的属性

方法一: /// /// 实体属性处理 /// public class PropertyHandle { #region 反射控制只读、可见属性 //SetPropertyVisibility(obj, "名称 ", true); //obj指的就是你的SelectObject, “名称”是你

勿忘初心 1万+

【深度学习驱动流体力学】采集OpenFOAM仿真数据作为AI模型训练数据集与卷积神经网络搭建到预测(一站式完整代码实现)

采集OpenFOAM仿真数据作为AI模型训练数据集与卷积神经网络搭建到预测(一站式完整代码实现)

源代码杀手的博客 1414

PropertyGrid自定义控件

PropertyGrid是一个很强大的控件,使用该控件做属性设置面板的一个好处就是你只需要专注于代码而无需关注UI的呈现,PropertyGrid会默认根据变量类型选择合适的控件显示。但是这也带来了一个问题,就是控件的使用变得不是特别灵活,主要表现在你无法根据你的需求很好的选择控件,比如当你需要用Slider控件来设置int型变量时,PropertyGrid默认的模板选择器是不支持的。网...

dijiao7977的博客 647

Pointnet++改进90:2025最新改进模块-EVA模块

本教程提出了一种改进PointNet++特征提取模块的方法,通过在PointNetSetAbstraction模块中加入NAMAttention注意力机制,显著提升了模型性能。具体改进包括:1)新建eva.py文件,实现了包含SDLSKA、CKS等关键组件的EVA模块;2)在pointnet2_utils.py中添加Conv和PointNetSetAbstractionAttention类,整合注意力机制;3)修改pointnet2_sem_seg.py模型结构。这种改进方法降低了实现难度,同时保持了33F

AIcurator的博客 361

ICP-10111气压传感器原理图设计,已量产(压力传感器)

在最近的室内导航定位项目中,我们需要一款能捕捉厘米级垂直高度变化的气压传感器 —— 毕竟室内环境里,哪怕是单个台阶的高度差都得精准识别。对比了几款器件后,最终选定了 ICP-10111:它 ±1Pa 的压差精度刚好能把高度差分辨到 8.5cm,0.4Pa 的低压力噪声能让数据输出足够稳定,再加上 0.5Pa/℃的低温漂特性,长期工作的可靠性也能满足需求。下面聊聊这套适配 ICP-10111 的硬件电路设计细节。

不脱发的程序猿 333

PropertyGrid实现文件选择项

原来公司的一段代码,现在给朋友写的软件里也用上了,看样用处挺多,所以保存一下。 自定义属性类: using System; using System.Collections.Generic; using System.Text; using System.Drawing.Design; using System.Windows.Forms.Design; using S...

alvin2901的博客 1316

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

C# PropertyGrid控件应用心得

转自:http://blog.youkuaiyun.com/luyifeiniu/article/details/5426960 最近项目中做一模块时偶发奇想,希望使用propertygrid的控件实现类似visual studio的属性样式,于是拿来一用,发现还真不是自己想象的那么简单,如果要实现一个比较好的展示,还真的需要不少技巧,通过自己的实践和网络的力量,“逢山开道,遇水搭桥”,总算是摸出一

kevin3683的专栏 1693

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

上一篇: C++开发学习笔记:map的基本操作和用法
下一篇: C#开发学习笔记:获取项目程序及运行路径的方
JustWantToFly
博客等级 码龄10年 42粉丝 81原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值