码迷,mamicode.com
首页 > Windows程序 > 详细

C# WinForm PropertyGrid用法

时间:2016-10-26 22:19:28      阅读:387      评论:0      收藏:0      [点我收藏+]

标签:generic   棋盘   ring   ida   hive   net   自定义类   识别   src   

关于C# PropertyGrid的用法没有找到,找到一个C++的用法。
模仿着使用了一下,感觉挺不错,分享一下。

基本用法:
拖个PropertyGrid,绑定一个属性类就行了。

大气象

Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PropertyGridApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            propertyGrid1.SelectedObject = new Go();
        }

        class Go
        {
            private string _Hi = "hi";
            public string Hi
            {
                get { return _Hi; }
                set { _Hi = Hi; }
            }
        }

    }
}

它能自动识别Go类中的属性,并且自动关联。

技术分享

对属性进行分类并加注释:

大气象

Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->class Go
{
    private float _TieMu = 5.5f;
    private string _Rule = "数子法";
    [CategoryAttribute("规则"), DescriptionAttribute("贴目")]
    public float TieMu
    {
        get { return _TieMu; }
        set { _TieMu = TieMu; }
    }
    [CategoryAttribute("规则"), DescriptionAttribute("计算法")]
    public string Rule
    {
        get { return _Rule; }
        set { _Rule = Rule; }
    }

    private int _Black = 0;
    private int _White = 0;
    [CategoryAttribute("围棋"), DescriptionAttribute("")]
    public int Black
    {
        get { return _Black; }
        set { _Black = Black; }
    }
    [CategoryAttribute("围棋"), DescriptionAttribute("")]
    public int White
    {
        get { return _White; }
        set { _White = White; }
    }
}

技术分享

使用Color类型可以显示颜色选择下拉框,使用Image类型可以显示图片选择对话框,真强大。

大气象

Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->private Color _BoardColor = Color.Yellow;
[CategoryAttribute("围棋"), DescriptionAttribute("棋盘颜色")]
public Color BoardColor
{
    get { return _BoardColor; }
    set { _BoardColor = BoardColor; }
}

private Image _Background;
[CategoryAttribute("围棋"), DescriptionAttribute("棋盘背景")]
public Image Background
{
    get { return _Background; }
    set { _Background = Background; }
}

技术分享技术分享

另外是自定义类型,比如枚举.

源码:http://files.cnblogs.com/greatverve/PropertyGridApp.rar

参考:

http://blog.csdn.net/xoyojank/archive/2009/07/04/4322167.aspx

C# WinForm PropertyGrid用法

标签:generic   棋盘   ring   ida   hive   net   自定义类   识别   src   

原文地址:http://www.cnblogs.com/rainbow70626/p/6002065.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!