© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
8 replies
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)
{

}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ MultiLine error on custom user control WinForms
C#CC# / help
9mo ago
Add custom font in c# winforms
C#CC# / help
2y ago
I am trying to add a custom cursor to my winforms app
C#CC# / help
2y ago
Winforms: add an existing form
C#CC# / help
2y ago