Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

.NET newbie alert

Using Visual C# 2008 Express Edition I have accidentally created a click event for a button. I then deleted the automatically-created method code, which resulted in an error saying that the function, which had now been referenced in the form loading code, could no longer be found.

Deleting the following line from the Form1.Designer.cs file's InitializeComponent() function...

this.btnCopy.Click += new System.EventHandler(this.btnCopy_Click);

... seems to do the trick, however, it makes me feel very dirty because of the following warning at the beginning of the #region:

/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.

I haven't been able to find a way to do this using the form designer, which I assume is the means implied by this warning. What is the correct way to do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
362 views
Welcome To Ask or Share your Answers For Others

1 Answer

You do have to be careful when working in the designer.cs files but you don't have to feel dirty about it (when I make the same mistake it is just easier to fix it the designer.cs file). You can do it visually like this:

  1. Open the form in the form designer.
  2. In the form designer, click the button of interest.
  3. Press F4 (or right click the button and then click properties). The properties pane should show up.
  4. At the top of the properties pane, click the lightning bolt. This shows the events for the button.
  5. Find the click event and clear its handler.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...