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