WinForms : adding a form1 object as a parameter of radiobutton event causes error in the Designer

Joined
Sep 26, 2022
Messages
16
Programming Experience
1-3
Here are the code snippeds, form1.cs:
1670159589969.png

And, here is the Designer ERROR :
1670147405046.png

If I pass a form object as an parameter into a normal method argument, it works fine this way, no designer & eventhandler error occurs.

However if I use events like RadioButton Checked Changed, then I get this EVENT HANDLER & DESIGNER ERROR.

How do I fix it? I want to use form objects and their events together at the same time here, but there is an error.
 

Attachments

  • 1670147300302.png
    1670147300302.png
    99 KB · Views: 14
Last edited:
Of course it does. You don't get to choose what parameters an event handler has. When an object raises an event, it invokes a method and passes arguments for the parameters. How do you expect that object to magically know that it needs to pass an argument for that parameter when the person who wrote the code for that object had no knowledge of it?

If you want to access the form that the control raising the event is on then use the sender parameter. That is the object that raised the event, so you can cast it as type Control or a more specific type and then call its FindForm method.
 

Latest posts

Back
Top Bottom