• 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 1:
                            _ReadWrite_06 = Buchang.标准溶液;
                            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.标准溶液:
                            _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.标准溶液;
                            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
            {
                标准溶液 = 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

    运行后显示效果:

  • 相关阅读:
    64码高清网络电视V2.4.2
    无线网络探测V1.22
    居民身份证号码查询系统
    ORA-12505 TNS:listener does not currently know of SID given in connect descriptor
    weblogic项目部署问题--Deployment could not be created. Deployment creator is null.
    ORA-01461: can bind a LONG value only for insert into a LONG column 解决方法
    前端基础知识学习第五节(Vue篇)
    前端基础知识学习第三节
    前端基础知识学习第二节
    你真的会用parseInt方法吗?
  • 原文地址:https://www.cnblogs.com/qq458978/p/4607725.html
Copyright © 2020-2023  润新知