3.c# custom attribute pop-up edit box

Common properties and editing methods

Generally bool, color, font, enum (enumeration), string[], int, double

When you use it, you will find that there are different ways to edit attributes
. Values, strings, and characters can be entered directly.
Insert image description here
Bool, enumeration, etc. are selected in the drop-down box,
Insert image description here
and font, color, and string[] are pop-up boxes. The way to edit, of course, there are many items, collections, etc. will not say

Insert image description here
Font and color are both original types.

Custom attribute pop-up box editing

Here we want to define a custom type, which can also be edited in a pop-up box
First create a class PersonInfo.cs for declaration as a custom attribute

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CustomAttrForm
{
   
    
    
    public class Person
    {
   
    
    
        public string Name {
   
    
     set; get; }

        public int Age {
   
    
     set; get; }

        public Sex Sex {
   
    
     set; get; }

        [Browsable(true)]
        [TypeConverter(typeof(ExpandSortConverter))]	//可以扩展转换器
        [Editor(typeof(BirthPlaceEditor), typeof(UITypeEditor))]	//弹出框编辑
        public BirthPlace birthPlace {
   
    
     set; get; }

    }


    public class BirthPlace
    {
   
    
    
        public BirthPlace()
        {
   
    
    

        }

        public BirthPlace(string Province,string City, string County)
        {
   
    
    
            this.Province = Province;
            this.City = City;
            this.County = County;
        }

        public string Province {
   
    
     set; get; }

        public string City {
   
    
     set; get; }

        public string County {
   
    
     set; get; }

    }

    public enum Sex {
   
    
     Boy,Girl}


}

The core lies in BirthPlaceEditor, the property editor BirthPlaceEditor.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace CustomAttrForm
{
   
    
    
    public class BirthPlaceEditor : UITypeEditor
    {
   
    
    

Guess you like

Origin blog.csdn.net/adsd1233123/article/details/128004262