PropertyGrid 控件使用方法
生活随笔
收集整理的這篇文章主要介紹了
PropertyGrid 控件使用方法
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?
編寫(xiě)一個(gè)對(duì)象,后面?zhèn)鬟f給 PropertyGrid 來(lái)顯示:
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 .標(biāo)準(zhǔn)溶液;[CategoryAttribute("讀寫(xiě)存儲(chǔ)區(qū)"), DisplayName("06 補(bǔ)償類(lèi)型")]public Buchang ReadWrite_06{get {switch (BuchangValue){case 1:_ReadWrite_06 = Buchang.標(biāo)準(zhǔn)溶液;break;case 2:_ReadWrite_06 = Buchang.自然水;break;case 3:_ReadWrite_06 = Buchang.純水;break;case 4:_ReadWrite_06 = Buchang.其他溶液;break;default:break;}return _ReadWrite_06; }set{switch (value){case Buchang.標(biāo)準(zhǔn)溶液:_BuchangValue = 1;break;case Buchang.自然水:_BuchangValue = 2;break;case Buchang.純水:_BuchangValue = 3;break;case Buchang.其他溶液:_BuchangValue = 4;break;default:break;}_ReadWrite_06 = value;}}private int _BuchangValue = 1;public int BuchangValue{get{return _BuchangValue;}set{switch (value){case 1:ReadWrite_06 = Buchang.標(biāo)準(zhǔn)溶液;break;case 2:ReadWrite_06 = Buchang.自然水;break;case 3:ReadWrite_06 = Buchang.純水;break;case 4:ReadWrite_06 = Buchang.其他溶液;break;default:break;}_BuchangValue = value;}}public enum Buchang{標(biāo)準(zhǔn)溶液 = 0,自然水 = 1,純水 = 2,其他溶液 = 3,}} } View Code?
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 = 4;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();}} } View Code?
運(yùn)行后顯示效果:
?
轉(zhuǎn)載于:https://www.cnblogs.com/qq458978/p/4607725.html
總結(jié)
以上是生活随笔為你收集整理的PropertyGrid 控件使用方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 使自定义控件居中于父容器的计算公式
- 下一篇: [算法导论]练习16.1-4 活动教室分