I have a user-defined button, and it may have a Style property which I choose in properties window a value for it and depending on that value its Image and style will change.
How can I make this property to have some predefined and fixed values in a drop down list in properties window? and selecting a value causes running a method
-details:
this button may gets specified appearance such pause and play styles. so I made a class for styles:
// style of the button; pause, play, reset, etc
public abstract class ButtonStyle
{
public abstract Image GetImage();
}
// inherited classes of class ButtonStyle
public class PauseButtonStyle : ButtonStyle
{
public override Image GetImage()
{
return CustomButtonLibrary.Properties.Resources.PauseButton;
}
}
public class PlayButtonStyle : ButtonStyle
{
public override Image GetImage()
{
return CustomButtonLibrary.Properties.Resources.PlayButton;
}
}
And there is a method in the button for setting the specified style (pause,play,…):
public void SetStyle(ButtonStyle style)
{
button1.Image = style.GetImage();
}
Now how can I have a property for this custom button in properties window that this property has some default values like pause, play,etc and selecting it causes changing the button’s style (with running SetStyle method)
I would make an enum and expose that as the
Styleproperty. Then, have a internal dictionary that keys off the enum value to choose the appropriateButtonStyleobject to pass to yourSetStylemethod.