4

When running a program I need to see every time a certain button is disabled and step through the code at that point.

If I set a breakpoint with a condition (ex: only hit when button1.enabled=false) it will only hit in that specific place.

Is it possible to set a breakpoint on the entire program so that i can see when a condition changes across many forms and locations?

Dman
  • 553
  • 1
  • 11
  • 33
  • Not sure about a global way to do it, but you can Right Click on Button1 in the code and select "Find All References". Then you can use that list to find all the lines of code you're interested in and set Breakpoints accordingly. – Idle_Mind Dec 15 '14 at 16:25

2 Answers2

4

You can't set one breakpoint and have it apply to every line of the file, but you can set a breakpoint on the setter of Enabled and then filter it to a specific filter condition. That would give you the desired result. (Note, you might need to turn off "Just my code", see this question for more info)

Set a breakpoint using the "New Breakpoint At Function" as described here, though in Visual Studio 2013, I seem to need to use a slightly different notation:

enter image description here

Then set the breakpoint to funtion:

 System.Windows.Forms.Control.Enabled

in C# or for VB.NET:

 System.Windows.Forms.Control.set_Enabled(bool)

(You seem to need to use the class that actually defines the property, which in case of the Button class' Enabled property, is the Control class the Button inherits from.

Ignore the warning about it not being able to find the function (it does that for properties somehow), or uncheck the Intellisense lookup.

Now look up the breakpoint in the Breakpoints list and customize the condition so it breaks on the right button

enter image description here

Use the Name property (or any other filter that makes the breakpoint unique) to trigger when you need it to:

enter image description here

When it breaks, it will break in the sources of Control (if you have Framework Source Stepping enabled), which may be confusing. Use the Stack Trace window to find the location where the method was invoked exactly.

enter image description here

Another way of setting the breakpoint is through the Stacktrace window. Set a breakpoint on any line that has your property of interest on it. Launch the debugger and make it break on that line, now use "Step into Specific" to step into the property that you want to break on.

enter image description here

Use the "Stack" window to generate the breakpoint for you:

enter image description here

Community
  • 1
  • 1
jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • Excellent, but not sure what to put in the breakpoint condition, so far I have when: "this.btnReish.Enabled=false" in the condition, but not hitting – Dman Dec 15 '14 at 17:02
  • Based on his example, you'd need `this.Name == "btnReish"`. – Idle_Mind Dec 15 '14 at 17:07
  • Make sure you disable "Just my code" in the Debugger settings of Visual Studio and relaunch your debug session: http://stackoverflow.com/a/2192740/736079 You might need to adjust your location to `System.Windows.Forms.set_Enabled(bool)` depending on your visual studio version. – jessehouwing Dec 15 '14 at 17:08
  • I spun up a VB.NET project to test and had to use: `System.Windows.Forms.Control.set_Enabled(bool)` as location and `this.Name=="Button1"` as condition. – jessehouwing Dec 15 '14 at 17:28
  • Does your breakpoint show a red circle with a white cross? Or a white circle with a red cross? The former should mean that it now works, the latter that there is an error with the breakpoint for some reason. – jessehouwing Dec 15 '14 at 17:34
0

Since in your case you're looking to break on a function from the Microsoft .NET framework, there is another way. Enabled Framework Source Stepping.

Open the Visual Studio Debugger options and enable "Framework Source Stepping" and disable "Just My Code". enter image description here

Then enable the Microsoft Symbol Servers in as instructed. Now load up your application under the debugger and wait for the symbol files to be downloaded. enter image description here

set a break point anywhere in your code that is somehow related to System.Windows.Forms (The constructor of your MainForm for example) and rightclick any function from the "System.Windows.Forms" assembly to load the symbols for that assembly. This will allow you to step into the "Enabled" property and set a break point there. enter image description here enter image description here

A full tutorial can be found here: http://blogs.msdn.com/b/sburke/archive/2008/01/16/configuring-visual-studio-to-debug-net-framework-source-code.aspx

jessehouwing
  • 106,458
  • 22
  • 256
  • 341