N
N
Nazarevsky2021-05-17 20:07:35
C++ / C#
Nazarevsky, 2021-05-17 20:07:35

How to remove an event handler in Windows Forms?

Hello!
I recently started to understand Windows Forms and ran into the following problem. It happens that when creating a button, you accidentally click on it a couple of times and an event handler of the type is automatically created:

private void button1_Click(object sender, EventArgs e)
{

}

Can you please tell me how to remove an unnecessary event?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Korotenko, 2021-05-17
@Nazarevsky

Right click find references and delete this line. The other way is just to remove this function and the compiler will complain about an error, go there and double again. Select the third button in the designer and look at the handler in the properties, just delete it there. All these methods are equivalent, there is still truth

C
cicatrix, 2021-05-18
@cicatrix

The assignment of event handlers in WF by default by the environment is done in the InitializeComponent() method - its call is placed in the form's constructor. You need to remove it from it, and simply delete the body of the method.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question