C#C
C#3y ago
kaypee90

❔ How to add custom attributes to Winforms control events

I have added a custom attribute to a winforms control event but it is not being triggered. What is the right way to do that.

[AttributeUsage(AttributeTargets.Method)]
public class EventTimeAttribute : Attribute
{
private string EventName { get; set; }
public EventTimeAttribute(string eventName)
{
EventName = eventName;
Console.WriteLine($@"{DateTime.Now.ToShortDateString()}: {eventName}");
}
}



Using the attribute:
[EventTime("lvAccounts_SelectedIndexChanged")]
private void lvAccounts_SelectedIndexChanged(object sender, EventArgs e)
{

}
Was this page helpful?