pax
pax

Reputation: 1903

How remove unnecessary lines

this is my code:

public RegForm()
{
    InitializeComponent();
}

private void label1_Click(object sender, EventArgs e)
{
}

private void label10_Click(object sender, EventArgs e)
{
}

private void label28_Click(object sender, EventArgs e)
{
}

private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
}

private void label29_Click(object sender, EventArgs e)
{
}

private void label30_Click(object sender, EventArgs e)
{
}

private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
}

I would like to remove all the unnecessary lines of code for the labels that just came up out of nowhere for no reason and do absolutely nothing. But when I delete them - it's all errors. I'm a beginner, so please go easy on me. Thank you in advance.

Upvotes: 1

Views: 430

Answers (3)

mybirthname
mybirthname

Reputation: 18127

This are auto generated events which are created when you double click on control or some other action is performed on the controls in the design view.

Remove the lines from code behind and also remove them from *.designer.cs file.

IF you build the application after the removing of the lines and check errors: You can click on every error and it will leads you to the place which should be deleted !

Upvotes: 3

Rahul
Rahul

Reputation: 77896

If those are unnecessary then just go ahead and delete them from your code behind *.cs file. You will also have to delete the event registration from the corresponding *.designer.cs file and because of the same thing you are getting error (that you are not removing the corresponding event registration from designer file).

You can as well do the same from Designer window by select the control -> press F4 -> go to the event pane by clicking the lighting bolt icon -> remove the event registration.

enter image description here

Upvotes: 2

Grant Winney
Grant Winney

Reputation: 66479

To remove those empty event handlers:

  1. Switch to the designer view,
  2. Select each label, one at a time,
  3. Look at the properties window (press F4 if it's not visible), and check out the events view
  4. Find the click event, right-click and choose "reset".

enter image description here

Be careful when you're selecting your different controls in the designer.

If you double-click by accident, you end up creating an empty event handler for whatever the default event is for a particular control. In the case of a Label, it happens to be the Click event.

Upvotes: 4

Related Questions