Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug winforms designer

My question is not how to debug during design time. I actually want to debug through the events available in designer. I know that the form has load and other type of events. Is there any events in windows forms designer like init, load, etc ?

I have done a similar debugging in ASP through user controls. It allows us to view the output HTML of a user control before adding it to the designer.

I know windows forms and ASP are different but there should be some event to check values of Controls before actually rendering it.

My Form takes a long time to open in the VS designer. So I attached a debugger to VisualStudio (devenv.exe), set a breakpoint in my Form’s InitializeComponent to step through it to see what the problem is. However, the breakpoint is not getting hit.

like image 916
Kira Avatar asked May 20 '16 12:05

Kira


People also ask

How do I debug a Visual Studio designer?

To debug project code running in the designerOpen a new instance of Visual Studio, and then open a second instance of your project. Set a breakpoint in your project code. In the new instance of Visual Studio, on the menu bar, choose Debug > Attach to Process.

How do you debug a method in C#?

To start debugging, select F5, or choose the Debug Target button in the Standard toolbar, or choose the Start Debugging button in the Debug toolbar, or choose Debug > Start Debugging from the menu bar. The app starts and the debugger runs to the line of code where you set the breakpoint.


2 Answers

To debug design-time of your windows forms project:

  • Right click on your project in solution explorer and open Properties.
  • In the property page select the Debug tab.
  • In the Start Action section, select Start external programand then click on button to browse for the Visual Studio executable file devenv.exe which is located in a path like "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe"
  • Save project and then run using F5. A new instance of visual studio will be opened.
  • Open the project using new instance. Which enables you to debug the previous instance of visual studio containing your project.
  • Put breakpoints in the files which you want to debug in instance.

When may I find this approach useful?

  • When you have an exception in design-time.
  • When you want to debug the behavior of a Designer or a TypeConverter or a UiTypeEditor at design time.

For more information:

  • Walkthrough: Debugging Custom Windows Forms Controls at Design Time
like image 84
Reza Aghaei Avatar answered Sep 19 '22 09:09

Reza Aghaei


To debug in designer you need to put a breakpoint on top of designer code.

Then start your application and it will stop at the breakpoint.

Press F11 to move one line at the time.

enter image description here

like image 36
Claudius Avatar answered Sep 22 '22 09:09

Claudius