visual-studio 用于清除所有的 Visual Studio 即时窗口命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/714503/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio immediate window command for Clear All
提问by Scott Ivey
Is there a command to clear the immediate window in Visual Studio?
是否有清除 Visual Studio 中的即时窗口的命令?
I hate having to grab the mouse for a right click menu there - would rather just type "cls" or something.
我讨厌在那里抓住鼠标右键单击菜单 - 宁愿只输入“cls”或其他东西。
回答by lc.
To clear the immediate window, you can use >cls, which is a predefined command aliasto >Edit.ClearAll.
要清除即时窗口,你可以使用>cls,这是一个预定义的命令别名来>Edit.ClearAll。
The MSDN articlelists all predefined aliases and you can define your own, too. (For VS 2010 and earlier, custom aliasesare described in a separate article, though.) Scanning through, there's a whole slew of them, some of which might even have their roots in MS-DOS DEBUG.EXE (specifically >d, >g, >p, >q, and >tcome to mind).
MSDN 文章列出了所有预定义的别名,您也可以定义自己的别名。(不过,对于 VS 2010 及更早版本,自定义别名在单独的文章中进行了描述。)仔细浏览,其中有一大堆,其中一些甚至可能源自 MS-DOS DEBUG.EXE(特别是>d, >g, >p, >q,和 >t想到)。
Also worth noting, as it's only two keys to press: Context menu > Clear All invokes the same command and it can be navigated using keyboard. In the immediate window, you can press context-menu, L.
同样值得注意的是,因为只需按下两个键:上下文菜单 > 全部清除调用相同的命令,并且可以使用键盘进行导航。在即时窗口中,您可以按context-menu, L。
If you don't have a context-menukeyon your keyboard (you know, the one between right-altand right-ctrl), you can use shift+ F10instead.
如果您的键盘上没有context-menu键(您知道,介于right-alt和之间right-ctrl),您可以使用shift+F10代替。
回答by Martin Brown
>cls 
seems to do it for me.
似乎为我做。
回答by rossco78
- Place the mouse cursor in the Immediate Window.
- Right click on the mouse and select "Clear All".
- 将鼠标光标放在立即窗口中。
- 右键单击鼠标并选择“全部清除”。
回答by Scott Ivey
found it...
找到了...
">Edit.ClearAll"
">Edit.ClearAll"
or
或者
">cls"
">cls"
回答by user1330634
Here is how to do it at run time:
以下是如何在运行时执行此操作:
- Reference the EnvDTE dlls in your application. 
- Create and then use this function as necessary. 
- 在您的应用程序中引用 EnvDTE dll。 
- 创建并根据需要使用此函数。 
Public Sub ClearImmediateWindow()
  Try
    Dim vsWindowKindImmediateWindow As String _ 
          = "{ECB7191A-597B-41F5-9843-03A4CF275DDE}"
    Try
      Dim obj As Object = System.Runtime.InteropServices.Marshal._ 
                          GetActiveObject("VisualStudio.DTE.10.0")
      If obj IsNot Nothing Then
        Dim DTE2 As EnvDTE80.DTE2 = CType(obj, EnvDTE80.DTE2)
        For Each wndw As EnvDTE.Window In DTE2.Windows
          If wndw.ObjectKind = vsWindowKindImmediateWindow Then
            wndw.Activate()
            DTE2.ExecuteCommand("Edit.ClearAll")
            Exit For
          End If
        Next
      End If
    Catch comEx As COMException
      ' Not running from within the VS IDE?
    Catch ex As Exception
      Throw ex
    End Try
  Catch ex As Exception
    ' Handle this as you desire.
  End Try
End Sub
  End Sub
回答by Mojtaba Rezaeian
For visual studio 2012 I use:
对于 Visual Studio 2012,我使用:
Public Sub ClearImmediateWindow()
    Dim dte As EnvDTE80.DTE2 = Marshal.GetActiveObject("VisualStudio.DTE.11.0")
    dte.Windows.Item("Immediate Window").Activate() 'Activate Immediate Window  
    dte.ExecuteCommand("Edit.SelectAll")
    dte.ExecuteCommand("Edit.ClearAll")
    Marshal.ReleaseComObject(dte)
End Sub
to automatically clear immediate window from codes(requires to add DTE references to project). If it not works try VisualStudio.DTE.8.0, VisualStudio.DTE.9.0, ...according to your visual studio version.
自动清除代码中的即时窗口(需要向项目添加 DTE 引用)。如果它不起作用,请根据您的 Visual Studio 版本尝试VisualStudio.DTE.8.0, 。VisualStudio.DTE.9.0...
回答by Wade Hatler
I used the last answer just about verbatim and it works, although I wanted the focus back on where it was. Here's the very slightly improved C# version. I enable it with a configuration switch.
我几乎逐字使用了最后一个答案并且它有效,尽管我希望将注意力集中在它的位置上。这是稍微改进的 C# 版本。我使用配置开关启用它。
#if DEBUG
    if (GetIni("Debug", "ClearImmediateWindow", true)) {
        try {
            var dte = (EnvDTE.DTE) Marshal.GetActiveObject("VisualStudio.DTE.15.0");
            var me  = dte.ActiveWindow;
            dte.Windows.Item("Immediate Window").Activate();
            dte.ExecuteCommand("Edit.ClearAll");
            me.Activate();
        }
        catch { /* Meh! */ }

