• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C#,Winform中PropertyGrid控件的使用

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

 

PropertyGrid的功能不用我多说了,看名字就可以知道个大概,在这里就谈谈它的一些功能使用。

假设目前有一个PropertyGrid控件PropTableColumn,那么进行属性绑定只需要一句话:

this.PropTableColumn.SelectedObject = ... ;

其中...表示需要进行绑定的对象,PropertyGrid使用的广泛性也主要体现在对象的设计上.

假设我们目前设置了一个类ABSControlsSettings用于绑定,代码如下:
public class ABSControlsSettings
    {
        public ABSControlsSettings()
        {
         }        
     }那么这个类就可以用于绑定,只是什么属性都没有而已,OK,现在我们加入一个ID属性的维护输入,其代码和加入一个普通的类属性没有什么区别
private string _ControlID;
public string ControlID
        {
            get { return _ControlID; }
            set { _ControlID = value; }
         }此时我们可以通过添加一系列属性来完善它,如
CategoryAttribute("System")
ReadOnlyAttribute(false)
DescriptionAttribute("Controll's ID")

这个只是最普通的属性,如果属性需要设置true or false,那么只需要这样设置
private bool _Needcheck;
public bool Needcheck
        {
            get { return _Needcheck; }
            set { _Needcheck = value; }
         }
如果是一个需要进行多项选择,如同BorderStyle之类的参数,可以通过枚举属性来实现
private ControlTypeEnum _ControlType = ControlTypeEnum.Label;
public ControlTypeEnum ControlType
        {
            get { return _ControlType; }
            set { _ControlType = value;}
         }
public enum ControlTypeEnum
{
        /**//// <summary>
        /// 标签
        /// </summary>
         Label = 1,
        /**//// <summary>
        /// 文本框
        /// </summary>
         TextBox = 2
}


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
c#泛型集合Dictionary发布时间:2022-07-14
下一篇:
c#实现WebSocket发布时间:2022-07-14
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap