c# propertyGrid 出现checkbox属性的效果
来源:互联网 发布:java web出卷考试系统 编辑:程序博客网 时间:2024/06/05 17:07
怎样让C# propertyGrid控件,对于其bool型属性,让其以checkbox的样式出现如下图所示
先自定义一个类,用于更改propertyGrid属性样式。这是某国外网站的描述
Display a check-box next to a Boolean value in the property grid.
This is a bit of a cheat because it is unfortunately not possible to host a control in the value area of the PropertyGrid. It is however possible to draw in that area if we have the correct UITypeEditor.
UITypeEditor has a couple of methods GetPaintValueSupported andPaintValue that enable you to draw a preview of the value. This is how the thumbnail of images is displayed next to image data in the property grid. By creating an editor and assigning it to your boolean value you can display a checkbox which shows a check-mark whenever the value is set to true.
其实就是通过C#画笔,画一个checkbox在它的bool值得属性里。具体代码如下public class CheckBoxInPropertyGridEditor : UITypeEditor
{
public overridebool GetPaintValueSupported(ITypeDescriptorContext context)
{
return true;
}
public overridevoid PaintValue(PaintValueEventArgs e)
{
ControlPaint.DrawCheckBox(e.Graphics,e.Bounds,((CheckBoxInPropertyGrid)e.Context.Instance).Isalarm? ButtonState.Checked : ButtonState.Normal);
}
}
这里先自定义一个类,将会应用到propertyGrid的bool值属性上。如见
public class CheckBoxInPropertyGrid
{
bool _cb;
[Editor(typeof(CheckBoxInPropertyGridEditor),typeof(System.Drawing.Design.UITypeEditor))]
public bool Isalarm
{
get{return _cb;}
set{_cb=value;}
}
}
然后在设置propertyGrid的属性
这样propertyGrid的Isalarm属性就会显示出checkBox的效果。
- c# propertyGrid 出现checkbox属性的效果
- C# 属性页 PropertyGrid
- C#自定义PropertyGrid属性
- C#自定义PropertyGrid属性
- C#自定义PropertyGrid属性
- C#自定义PropertyGrid属性
- C#自定义PropertyGrid属性
- C#自定义PropertyGrid属性
- C#自定义PropertyGrid属性
- C#自定义PropertyGrid属性
- C# PropertyGrid 加载动态属性
- PropertyGrid属性值的汉化
- 动态可订制属性的 PropertyGrid
- 动态可订制属性的 PropertyGrid
- C# 属性控件PropertyGrid应用心得
- C#基础系列:开发自己的窗体设计器(PropertyGrid显示中文属性名)
- C#基础系列:开发自己的窗体设计器(PropertyGrid显示中文属性名)
- C# 设计时动态改变实体在PropertyGrid中显示出来的属性
- C编译器剖析_1.1_ 语言、文法与递归
- caffe下面编译cudnn
- 一个典型的语音识别系统
- mfc设置控件日期格式
- JNI由浅入深_6_简单对象的应用
- c# propertyGrid 出现checkbox属性的效果
- Spring3.1 使用AspectJ实现AOP
- 面向对象的方式做采集程序
- javaweb上传
- Jsp 四种跳转方式
- char与byte的区别
- php统计某一目录下文件总数
- 忘掉过去,重新来过
- 慕课网 一个神奇好玩的网站