PropertyGrid 控件使用方法

编写一个对象,后面传递给 PropertyGrid 来显示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
namespace WindowsForms_PropertyGrid
{
public class UserPropertyClass
{
private string appVersion = "1.0";
[CategoryAttribute("版本"),
DefaultValueAttribute("1.0"),
ReadOnlyAttribute(true)]
public string AppVersion
{
get { return appVersion; }
set { appVersion = value; }
}
private Buchang _ReadWrite_06=Buchang .标准溶液; [CategoryAttribute("读写存储区"), DisplayName("06 补偿类型")] public Buchang ReadWrite_06
{
get {
switch (BuchangValue)
{
case :
_ReadWrite_06 = Buchang.标准溶液;
break;
case :
_ReadWrite_06 = Buchang.自然水;
break;
case :
_ReadWrite_06 = Buchang.纯水;
break;
case :
_ReadWrite_06 = Buchang.其他溶液;
break;
default:
break;
}
return _ReadWrite_06;
}
set
{
switch (value)
{
case Buchang.标准溶液:
_BuchangValue = ;
break;
case Buchang.自然水:
_BuchangValue = ;
break;
case Buchang.纯水:
_BuchangValue = ;
break;
case Buchang.其他溶液:
_BuchangValue = ;
break;
default:
break;
}
_ReadWrite_06 = value;
}
}
private int _BuchangValue = ;
public int BuchangValue
{
get
{
return _BuchangValue;
}
set
{
switch (value)
{
case :
ReadWrite_06 = Buchang.标准溶液;
break;
case :
ReadWrite_06 = Buchang.自然水;
break;
case :
ReadWrite_06 = Buchang.纯水;
break;
case :
ReadWrite_06 = Buchang.其他溶液;
break;
default:
break;
}
_BuchangValue = value;
}
}
public enum Buchang
{
标准溶液 = ,
自然水 = ,
纯水 = ,
其他溶液 = ,
} }
}

Winform 界面代码

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 WindowsForms_PropertyGrid
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
UserPropertyClass UserPropertyClass1;// = new UserPropertyClass();
private void MainForm_Load(object sender, EventArgs e)
{
UserPropertyClass1 = new UserPropertyClass();
UserPropertyClass1.BuchangValue = ;
propertyGrid1.SelectedObject = UserPropertyClass1;
timer1.Enabled = true;
} private void timer1_Tick(object sender, EventArgs e)
{
label2.Text = UserPropertyClass1.BuchangValue.ToString ();
} private void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
{
propertyGrid1.Refresh();
}
}
}

运行后显示效果:

PropertyGrid 控件使用方法

上一篇:M5311nbiot 模组入坑 (接入华为物联平台)


下一篇:2021牛客暑期多校训练营3 F 24dian