简体   繁体   中英

How do I make an image property in a winforms user control available in the properties window

On a winforms user control I've implemented I'd like to expose a property that allows a user to select an image that will be displayed on that control. I've tried exposing the property as both an Image and a Bitmap, I've tried specifying various attributes that looked promising, but no matter what I do, the property doesn't appear in the Properties window. What I'm looking for is the standard properties window interface that allows you to browse for an image to associate with the property. I suspect I'm going to kick myself for missing something obvious on this one, but I keep drawing a blank!

Here is an example that works for me:

    private Image image;

    public Image Image
    {
        get
        {
            return image;
        }
        set
        {
            image = value;
        }
    }

After you add the code to the UserControl , make sure you rebuild, then the Image property should appear in the Properties window.

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