How do I put a breakpoint at every MessageBox in my application?
问题:
回答1:
In Visual Studio IDE select menu Debug->New breakpoint->Breakpoint at Function...
Fill function field with text "MessageBox".
回答2:
Write a wrapper function around MessageBox, replace all your calls to MessageBox with that wrapper function, put a breakpoint inside your wrapper function.
回答3:
Select Debug > New Breakpoint > Break at function. This gives you a pop-up. Enter the fully qualified name of the method you want to break at. If it is a framework method, VS will tell you that the name can't be verified but you're still allowed to set it. E.g. to break on all System.Console.WriteLine enter that and accept the warning.
Now, when you run the application VS will stop in WriteLine, but since you probably do not have source files for that, VS will not jump to the right place. However, the call stack will be correct, and you can navigate backwards from there.
回答4:
This may not be possible but if you find and replace your MessageBox call and add a call (before the call to the MessageBox) to a function that has a breakpoint inserted then you can step on from there.
回答5:
You could do a find and replace:
replace
.ShowDialog();
with
.ShowDialog();
#ifdef dialogDebugging
System.Diagnostics.Debugger.Break();
#endif
Then define dialogDebugging in your project settings.
回答6:
Press ctrl-F to bring up the search dialog. Search for MessageBox.Show Right-click on the line of code and select Breakpoint -> Insert Breakpoint