How to Break All without changing window focus

2019-06-24 12:56发布

When testing a Windows Forms UI I shall often want to modify the code whilst it is running. Clicking on the "Break All" arrow does this for me, however Visual Studio always displays the Program.cs window and sets focus on the Application.Run() method, which kinda makes. However most of the time I have the code I want to edit right in front of me and having to close the Program.cs window is an annoyance and something I just don't want to do.

Is there an easy way to get the code to Break in the current window?

The only way I've found is to write a little macro that will pause the code, check if a new window has been created and, if so, close it. It's not ideal and it is rather rudimentary but it does the job. I've then just added a Toolbar command called "Break In Place" which sits in my Debug Toolbar. The code for the macro if anyone is interested is:

Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module Break
    Sub BreakInPlace()
        Dim activeWindow As EnvDTE.Window
        activeWindow = DTE.ActiveWindow

        DTE.Debugger.Break(True)

        If Not activeWindow Is DTE.ActiveWindow Then
            DTE.ActiveWindow.Close(vsSaveChanges.vsSaveChangesNo)
        End If
    End Sub
End Module

3条回答
手持菜刀,她持情操
2楼-- · 2019-06-24 13:37

To move back to your previous position use View->Navigate Backward (Ctrl + -) - once or max few times. It speeds a lot moving over latests cursor positions.

On the other hand View->Navigate Forward (Ctrl + Shift + -) lets move forward (as shown by the name).

查看更多
爷的心禁止访问
3楼-- · 2019-06-24 13:42

If you've multiple computers available (or possibly even Virtual machines) you could use a remote debugger.

查看更多
爷的心禁止访问
4楼-- · 2019-06-24 13:45

There is a free extension for this: Disable No Source Available Tab. Works great.

This small extension will prevent the tool window with title "No Source Available" from appearing in Visual Studio, and preserve the focus on the currently active tab.

查看更多
登录 后发表回答