23

in a .net windows forms project which has 100s of forms, and all those forms has countless custom made controls with base classes involved, its very difficult for me to know where a particular button is, i mean whats the form name which I'm looking at while i'm running the application, and where exactly is the button click event, in code, of the button that I just clicked. Is there a debugging feature in Visual Studio, which would just break the execution for me to the line where the click happened. Can I tell VS to break at which ever Click event comes next? (running visual studio 2012/13 these days).

thanks.

user734028
  • 1,021
  • 1
  • 9
  • 21

3 Answers3

27

Just before you click the button in the program do this:

Go to visual studio and pause the program. Just press the pause button. Then press F11 (Step Into).

Now press the button in the program, and you should be taken into the event handler.

Jakob Olsen
  • 793
  • 8
  • 13
  • 2
    so this is a very interesting solution, I have done this few times before. You just have to be careful in case your form has code behind the mouse move/hover events that code will break right after you have pressed f10/11 after you hit the pause button and have accidentally moved the mouse over that particular area. In my case the form paused at the Application.Run() statement, then I press F10, and I'm back on the running Form, now i carefully move the mouse to the Button in question and click it, and I'm dropped where I wanted to be. This tip/functionality should never be forgotten. Thanks. – user734028 Jan 05 '15 at 09:12
  • 1
    Just out of curiosity (I'm not much into the internals of visual studio): why do you have to step into *before* clicking on the button? – ilpelle May 09 '17 at 19:16
  • 6
    This works only if you have checked "Enable Just My Code" in Options | Debugging | General. – Jazimov Dec 20 '17 at 19:18
  • 1
    Does not work in VS2022, Probably because of Hot Reload. When code is paused, PowerPoint is frozen – Chandraprakash Nov 23 '21 at 21:24
1

For web projects, the technique suggested by Jakob Olsen will not really work, because you have no active thread in between the calls, and hence no thread to resume upon the next action. However what worked for me was:

  • Find some code (any code in your app) you know for sure it gets executed and set a breakpoint
  • Trigger this breakpoint, use SHIFT-F11 to step out until you're out of all methods
  • Now do the action of which you don't know what code is executed, and it will break
Damian Vogel
  • 1,050
  • 1
  • 13
  • 19
0

I can suggest partial solution.

If your click events are named like "Button_Click", open Breakpoints windows while in debug and create New breakpoint.

Click OK and you will see list of functions. Check them and click OK. On every function that you have selected will be created a breakpoint.

enter image description here

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Mike
  • 3,766
  • 3
  • 18
  • 32