If I have a project and I do not how design corresponds to the code is there a way to make the debugger break every time I press any button so I can quickly navigate to the right place in the code or am I asking for too much here?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can make a call to
System.Diagnostics.Debugger.Break()to tell any attached debuggers to break at that line.If none are attached, Windows will try to launch any registered debuggers. If not are registered, you’ll get an exception/crash of the application. So, don’t leave it in the code in production 🙂
e.g. (as per icemanind’s comment)
If you want to break on a click of any button, it gets a bit tricky. The easiest thing is to write a
Buttonwrapper class and overrideOnClickand put your Break call in there. For example:Once you add that class you can drag and drop it on the design surface. But, if you’ve already got code, you can edit the designer.cs file and replace
System.Windows.Forms.ButtonwithButtonWedge.Once in
OnClick, you can see where theClickevent will go by looking at the base classesEventsarray with theControl.EventClickkey. That will contain a multicast delegate that you can look at theMethodandTargetproperties to find out what has subscribed to thisClickevent. In other words, the name of the click handler at runtime will be:It doesn’t really put a break point in a particular
Clickevent but lets you know what’s going on and where…