Wordsmyth's Corner

How to Debug Designer Problems

Explains how to debug problems with the Visual Studio designer.

Designer Execution

The designer (the WYSIWYG part of the form IDE) actually compiles and runs the paint code of custom controls when you a) build, and b) open a a form. That's how it knows how to display them.

This execution occurs with the App's Base Directory set to the location of devenv.exe on your hard drive (e.g. c:/program files/Microsoft Visual Studio 8/Common7/IDE)

Resource Files

One of the implications of this is that if anything called by your app's paint code is looking for resource files or things from its base directory (for example, a config file or bitmap), they will not be found unless you put them in that directory.

Debugging the Designer

You can debug the designer using the built-in debugger. However, you must change the "Start Application" to devenv.exe rather than your own app.
  • Select the Main project
  • Select Properties / Debug
  • Under "Start Action", select External Program
  • Browse to devenv.exe on your hard drive
  • Set up breakpoints in your control code.
  • Launch the debugger.

The debugger will actually launch a new instance of Visual Studio. When you load your project in that new instance and open one of the forms, the form draw code will execute and you will hit your debugger breakpoints.