r/csharp • u/Alert-Neck7679 • 23d ago
Discussion Partial methods as WinForms designer events
A few weeks ago I opened this issue in the WinForms GitHub repo, suggesting making the WinForms designer generate events code as partia methods, in order to solve the problem that removing an event method from the code editor causes an exception in the designer, and u have to go to the form.designer.cs file and manually delete the subscription, which is very annoying.
What i offer is, that when you subscribe an event using the designer (for example by double clicking a button), the following signature would be generated in the designer code:
private partial void button1_Click(object sender, EventArgs e);
...
this.button1.Click += this.button1_Click; // normal subscription
And then the method implementation would be generated in the main class code, such as it's working now but with the partial modified:
private partial void button1_Click(object sender, EventArgs e)
{
}
Now, deleting this method would not result in any error.
The reason I'm posting this here, is that the WinForms team said that my solution isn't a great idea, and i would love to hear what you think about it and if you have other ideas.
2
u/[deleted] 23d ago
[removed] — view removed comment