2

I searched for a similar question and could not find any solutions. I am building a GUI based application in c#. I have a button and the onclick function for it. It is like this:

void button_choose_directory_Click(object sender, EventArgs e)//Choose folder where client will download the files
{
    FolderBrowserDialog chooseDirectory = new FolderBrowserDialog();

    if (chooseDirectory.ShowDialog() == System.Windows.Forms.DialogResult.OK)
    {
        downloadDirectory = chooseDirectory.SelectedPath;
        client.downloadDirectory = downloadDirectory;
        textbox_save_directory.Text = downloadDirectory;
    }
}

I accidentally double clicked again to that button and another function was automatically created.

 private void button_choose_directory_Click_1(object sender, EventArgs e)
 {

 }

Now if i delete this function program gives error and does not compile. How can i fix this? I do not want this unnecessary piece of code in my program.

Error message is like this:

FileTransferClient.Form1' does not contain a definition for    
'button_choose_directory_Click_1' and no extension method 
'button_choose_directory_Click_1' accepting a first argument of type 
'FileTransferClient.Form1' could be found (are you missing a using directive or an 
assembly reference?)    

Thanks

3
  • Read the error message. Commented Dec 22, 2013 at 17:08
  • 1
    CTRL+F for button_choose_directory_Click_1 and delete it. You've deleted method but it seems that there are still some event subscriptions. Commented Dec 22, 2013 at 17:09
  • @walkhard thanks, it looks like it automatically added an event subscription in another file. That works Commented Dec 22, 2013 at 17:11

3 Answers 3

3

You could right click the function you want to delete and choose "find usages". Visual Studio will take you to where it is being used and you can delete it first there. Then you can delete the method.

Sign up to request clarification or add additional context in comments.

Comments

1

Add This:

this.button_choose_directory.Click += new System.EventHandler(this.button_choose_directory_Click);
void button_choose_directory_Click(object sender, EventArgs e)//Choose folder where client will download the files
{
    FolderBrowserDialog chooseDirectory = new FolderBrowserDialog();

    if (chooseDirectory.ShowDialog() == System.Windows.Forms.DialogResult.OK)
    {
        downloadDirectory = chooseDirectory.SelectedPath;
        client.downloadDirectory = downloadDirectory;
        textbox_save_directory.Text = downloadDirectory;
    }
}

Remove This:

this.button_choose_directory.Click += new System.EventHandler(this.button_choose_directory_Click_1);

private void button_choose_directory_Click_1(object sender, EventArgs e)
{

}

Comments

1

Switch to the events in the properties window (flash icon). Delete the method name "button_choose_directory_Click_1" in the Click event. If the event method's body is empty, this deletes it as well. Otherwise delete the code manually.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.