When you have a multi-monitor device, you usually want to write code in one monitor and debug the program in another one. This is especially helpful when you want to debug some visual interface that is rendered by the code (or debug the Paint event, for WinForms apps).

But the program you’re debugging insists to open in the same monitor you are writing code. If you try to find some setting in Visual Studio to set the monitor to open the program, you won’t find any. So, what can be done in this case?

I’ve found two options, the code one, and the Windows one. Let’s start with the code option:

Add some code in the closing of the main form to save the window position and in the constructor of the form to restore the window position. This code could be used as a feature for your program: that way, the user can reposition and resize the window and the next time he opens it, it will be in the same position. If you don’t want this feature for the released version, enclose the code in the conditional compiler directive #if DEBUG ..#endif. You can check something like that for WPF in this CodeProject article: https://www.codeproject.com/Articles/50761/Save-and-Restore-WPF-Window-Size-Position-and-or-S (things should be similar for WinForms). With this code, you can move the window to the other monitor and start debugging there. Just remember to close the app normally, to save the current position. The next time you will debug the program, the window it will be in the same place.

For UWP, saving the last window position is the default behavior, so you don’t have to do anything in the code: just move the window to the new position and close it normally and everything is set.

The Windows option is very simple, but not quite at sight: when you have a multi-monitor disposition, there is a checkbox in the display settings that says “Make this my main display”. All you have to do in this case is to right click the desktop of any monitor, select “ Display settings”, select the monitor you want to open your programs, check this box and voilà, all programs will open by default on the selected monitor. The only side effect in this case is that the search bar and the system tray will move to this monitor, but I think that this is minimal and does not affect my daily use. Easy, no?


That way, you can edit code in one screen and run the program in the other. So, happy debugging!

O Visual Studio 2015 introduziu novas ferramentas de debugging de UI para as aplicações WPF, Windows 8.1 ou Windows 10: a Live Visual Tree e o Live Property Explorer.

Com estas duas ferramentas, você pode examinar a interface que é gerada em tempo de execução e também ver os valores das propriedades dos elementos.

Uma coisa muito interessante é que você, além de poder examinar as propriedades, também pode alterá-las dinamicamente, avaliando como fica a interface – sem dúvida, isso é uma mão na roda para quem quer fazer experiências com a UI e ver por que algo não ficou exatamente como esperado!

Se você quer saber mais sobre isso, pode dar uma olhada em meu vídeo no Channel 9: https://channel9.msdn.com/Series/Windows-Development/Ferramentas-de-Debugging-de-UI-no-VS-2015