Kevin O'Donovan
Kevin O'Donovan

Reputation: 1669

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!

Upvotes: 0

Views: 1015

Answers (1)

endofzero
endofzero

Reputation: 1818

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.

Upvotes: 1

Related Questions