简体   繁体   中英

How can I create a Usercontrol property that interacts with the Visual Studio property window?

I'm creating a Usercontrol (Windows, not WPF) and want to add my own custom color property, as show below. However any instances of this control show the property value of MyColor to be System.Drawing.SolidBrush in the property window.

    private Brush _MyColor = Brushes.Blue;
    [TypeConverter(typeof(System.Windows.Media.BrushConverter))]
    public Brush MyColor
    {
        get { return _MyColor; }
        set { _MyColor = value; }
    }

If I understand this correctly, you actually want to use a UITypeEditor , which allows you to have a custom editor for a property. The TypeConverter you're using allows you to specify strings, for example, and have them automatically converted to a Brush.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM