I want to add a custom property to a button in window form. Currently i am using following code to create my logic. but i want to create an enum value for a button control.
btnPartyDetails.Text = "View";
{}
btnPartyDetails.Text = "Add";
{}
btnPartyDetails.Text = "Delete";
{}
btnPartyDetails.Text = "Edit";
{}
I want to perform some action based on these values and i want to make a custom property for button so that i can use enum instead of using text match.
btnPartyDetails.ActionType= ActionType.View;
{}
btnPartyDetails.ActionType= ActionType.Add;
{}
btn开发者_开发百科PartyDetails.ActionType= ActionType.Delete;
{}
btnPartyDetails.ActionType= ActionType.Edit;
{}
I want to do something like this, where ActionType will be my enum
.
I also want to create custom event based on the value set. How can i do this ?
You will have to create a custom control and then inherit the button class. Then create your custom properties and / or events.
Check this or this out from MSDN
You can inherit from the control you want and extend it however you wish. AFAIK none of the controls are sealed classes in winform. So you could add additional properties and events. Something like:
public class MyTextBox : System.Windows.Forms.TextBox {
public string MetaMessage {get;set;}
public event SomeCoolEventHandler CoolEvent;
public delegate SomeCoolEventHandler(object sender, CoolEventArgs args);
}
public class CoolEventArgs: EventArgs{
....
}
You need to derive a new class from button
精彩评论