View Single Post
  #10 (permalink)  
Old February 12th, 2011, 05:34 PM
DrPurdum DrPurdum is offline
Friend of Wrox
Points: 1,166, Level: 13
Points: 1,166, Level: 13 Points: 1,166, Level: 13 Points: 1,166, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Sep 2008
Location: Indianapolis, IN, USA.
Posts: 234
Thanks: 0
Thanked 32 Times in 30 Posts

Hi scolty:

While I can't be positive, I put your code into VS and it did not behave as advertised. I put a breakpoint in the button Click event...and NEVER reached the breakpoint. This suggests that you wrote the Click event code before placing the button on the form.

The easiest way to check for such things is to display the form in the Design mode, and double click the button in question. If you see something like:


(notice the underscore 1 at the end), that tells me that the button control was not tied to the code. When you look at your source code, you will likely see code for two Click events: 1) The one you wrote, and 2) the one the compiler wants to execute when the user clicks the button. Alas, the compiler will ignore your code and execute the click event that doesn't have any code!

The fix is easy. Copy all of the code between the opening and closing braces for the Click event to the clipboard (e.g., highlight the code, then Ctrl-X). Now, delete the button click event so there's no code tied to the button in the source code file. Now switch back to the Design mode. Double-click on the button. This causes the button Click event fragment to be written back into the souce file. Now, place your cursor between the braces and press Ctrl-V to insert your code back into the button Click event. Your program should run fine now.
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)
The Following User Says Thank You to DrPurdum For This Useful Post:
scolty (February 12th, 2011)