b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

propertygrid?treeview增加子节点?propertygrid 屏蔽 dll?C#中使用Property

电脑杂谈  发布时间:2016-11-01 22:01:02  来源:网络整理

你是否正在寻找关于propertygrid的内容?让我把最吸引人的东西奉献给你:

C#中使用Property Grid(属性面板)控件

1.将Property Grid 控件添加到工具箱中

由于默认情况下Property Grid 控件没有显示在工具箱中所以需要手动添加。

propertygrid?treeview增加子节点?propertygrid 屏蔽 dll?C#中使用Property

图1 将Property Grid添加到工具箱(在工具箱上右键选择添加/移除项)

propertygrid?treeview增加子节点?propertygrid 屏蔽 dll?C#中使用Property

图2 在自定义工具箱对话框中选中propertygrid控件

2.编写自定义类,并跟propertygrid控件进行绑定

using System;
using System.ComponentModel;

namespace propertygridDemo
{
[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("用户信息"), DescriptionAttribute("设置消费者Email地址")]
public string Email
{
get
{
return email;
}
set
{
email = value;
}
}


{
get
{
return mark;
}
set
{
mark = value;
}
}

public Customer()
{
}
}
}

首先定义自定义类型的时候要引用System.ComponentModel命名空间,将使用到该命名空间中的一些Attribute类,在上面的例子中主要使用了DefaultPropertyAttribute,CategoryAttribute和DescriptionAttribute三个Attribute。

DefaultPropertyAttribute 指定组件的默认属性。

CategoryAttribute 指定当属性或事件显示在被一个设置为按分类顺序模式的 System.Windows.Forms.propertygrid 控件中时,用于给属性或事件分组的类别的名称。
DescriptionAttribute 指定属性或事件的说明,。

在编写自定类的时候所有的属性都应该有get 和set方法,如果没有get方法那么这个属性在PropertyGrid中不显示,没有set方法的话则为只读属性在propertygrid中无法设置该属性的值。

将自定义类与propertygrid控件进行绑定

使用propertygrid类的SelectedObject属性进行绑定

private void Form1_Load(object sender, System.EventArgs e)
{
Customer customer = new Customer();
customer.Name = "张三";
customer.Email = "zhangsan@sina.com";

propertygrid1.SelectedObject = customer;
}

运行结果:

propertygrid?treeview增加子节点?propertygrid 屏蔽 dll?C#中使用Property

posted @

以上就是关于propertygrid的全部内容,相信你一定会非常满意。


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-19941-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      热点图片
      拼命载入中...