DotNetBar的使用(三)PropertyGrid&AdvPropertyGrid

DotNetBar的使用(三)PropertyGrid&AdvPropertyGrid

PropertyGrid字面意思就是屬性表格網,也就是VS2010界面右側的屬性表的樣式。使用這個控件可以集中的控制控件的一些屬性和行爲,便於管理和使用。

 

1、首先拖入一個PropertyGrid控件,然後向窗體加載事件中FrmTest_Load()添加代碼

private void FrmTest_Load(object sender, EventArgs e)

        {

            propertyGrid1.SelectedObject = new Go();

        }

2、Go這個類中添加如下代碼

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 _01

{

    class Go

    {

        private string _Hi = "hi"; //聲明一個字符串

        public string Hi  //定義一個方法

        {

            get { return _Hi; }

            set { _Hi = Hi; }

        }

        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; }

        }

 

        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; }

        }

    }

}

 

 

3、顯示結果

 

4、使用PropertyGrid控件

新建一個類

[DefaultPropertyAttribute("Name")]

        public class Customer

        {

            private string name;

            private string email;

            private string mark;

 

            [CategoryAttribute("用戶信息"), DescriptionAttribute("設置姓名")]

            public string Name

            {

                get { return name; }

                set { name = value; }

            }

 

            [CategoryAttribute("用戶信息")]

            public string Email

            {

                get { return email; }

                set { email = value; }

            }

 

            [CategoryAttribute("用戶信息")]

            public string Mark

            {

                get { return mark; }

                set { mark = value; }

            }

 

            public Customer() { }

        }  

 

在窗體加載函數中添加代碼:

  private void FrmTest_Load(object sender, EventArgs e)

        {

            cus = new Customer();

            cus.Name = "瀟瀟";

            cus.Email = "[email protected]";

            this.propertyGrid1.SelectedObject = cus;

        }

5、結果顯示

 

參考資料:C# WinForm PropertyGrid用法

https://www.cnblogs.com/greatverve/archive/2010/10/26/csharp-propertygrid.html

地理信息科學

Writed By NX

QQ:1051926720


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章