Abhijeet Bhatt
Abhijeet Bhatt

Reputation: 57

Buttons showing 0 references winForm

I am just testing with the buttons and textboxes when I found that 2 buttons and a textbox isn't doing anything while the 2 buttons are working just fine.

0 references is showing over these buttons

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

The buttons does exist in Form (Design). those which are working shows 1 references

Upvotes: 0

Views: 991

Answers (1)

Caius Jard
Caius Jard

Reputation: 74700

Just because the method button1_Click (please name your buttons something better; it takes just a couple of seconds to rename a button after you add it to a form) exists in Form1.cs does not mean it's wired up to be the button click handler

  • Stop the app if it is running,
  • go into the forms designer,
  • get properties on the button (click on it and look in the grid in the right, or right click and choose properties if no grid is showing under solution explorer),
  • click the lightning bolt at the top of the properties grid,
  • scroll to the Click line,
  • drop down the setting to the right of the click and choose button1_Click
  • repeat for other unlinked buttons
  • ps this is how you can link multiple controls to the same handler

Oh, and take the time to rename all your buttons, so they are called like saveButton, cancelButton - it'll make your program a lot easier to read both for yourself and others you ask for help from eg on SO. Then rename your click handlers by focusing the caret on the method name and pressing Ctrl-R-R. Files like Form1 can be renamed and if the class inside them is also called Form1 then VS will offer to rename the class too, bonus! :)

Upvotes: 2

Related Questions