Reputation:
I have a UserControl
and have added a Property to it. But i want the Property to be added to the Properties Window
whenever my UserControl
is added to a form.
This is what i used to add the property
Image img;
public Image SetImage
{
get { return img; }
set { img = value; }
}
This works fine but the problem is that whenever a user wants to call this property, the user will have to call the class of the user control like
MyControl ctrl = new MyControl();
ctrl.Image = Image.FromFile("/*Path to Image*/");
but this will change all that property for all the Controls that have been added to that form but what i need is to map it to the UserControl so that whenever the user want to call it, the user will call it like
MyControl1.Image = Image.FromFile("/*Path to Image*/");
or
MyControl2.Image = Image.FromFile("/*Path to Image*/");
Pls how do i acheive this?
Upvotes: 0
Views: 251
Reputation: 10486
Add the [Browsable(true)]
tag (which is in System.ComponentModel
namespace inside System.dll
) to your desired property of your user control class:
public class YourUserControl
{
....
....
[Browsable(true)]
public Image SetImage
{
get { return img; }
set { img = value; }
}
}
Upvotes: 1