简体   繁体   English

如何清除调试器输出窗口Visual Studio 2012

[英]How to clear debugger output window Visual Studio 2012

For VS 2012, I am not able to clear debugger output window using following MSDN code , 对于VS 2012,我无法使用以下MSDN代码清除调试器输出窗口,

Basically I am not able to pass DTE2 object, to ClearExample . 基本上我无法将DTE2对象传递给ClearExample

public void ClearExample(DTE2 dte)
{
    // Retrieve the Output window.
    OutputWindow outputWin = dte.ToolWindows.OutputWindow;

    // Find the "Test Pane" Output window pane; if it doesn't exist, 
    // create it.
    OutputWindowPane pane = null;
    try
    {
        pane = outputWin.OutputWindowPanes.Item("Test Pane");
    }
    catch
    {
        pane = outputWin.OutputWindowPanes.Add("Test Pane");
    }

    // Show the Output window and activate the new pane.
    outputWin.Parent.AutoHides = false;
    outputWin.Parent.Activate();
    pane.Activate();

    // Add a line of text to the new pane.
    pane.OutputString("Some text." + "\r\n");

    if (MessageBox.Show("Clear the Output window pane?", "", 
        MessageBoxButtons.YesNo) == DialogResult.Yes)
        pane.Clear();
}

Using other SO links couldn't make it work for VS2012. 使用其他SO链接无法使其适用于VS2012。

Is it possible to programmatically clear the Ouput Window in Visual Studio? 是否可以以编程方式清除Visual Studio中的输出窗口?

Can the Visual Studio (debug) Output window be programatically cleared? 可以以编程方式清除Visual Studio(调试)输出窗口吗?

Here is how I implemented it. 这是我实现它的方式。 Note the reference to another question-answer that helped me. 请注意对另一个帮助我的问题的答案。

'   #region ClearOutputWindow
    /// <summary>
    /// Clear the Output window-pane of Visual Studio.
    /// Note: Causes a 1-second delay.
    /// </summary>
    public static void ClearOutputWindow()
    {
        if (!Debugger.IsAttached)
        {
            return;
        }

        //Application.DoEvents();  // This is for Windows.Forms.
        // This delay to get it to work. Unsure why. See http://stackoverflow.com/questions/2391473/can-the-visual-studio-debug-output-window-be-programatically-cleared
        Thread.Sleep(1000);
        // In VS2008 use EnvDTE80.DTE2
        EnvDTE.DTE ide = (EnvDTE.DTE)Marshal.GetActiveObject("VisualStudio.DTE.10.0");
        if (ide != null)
        {
            ide.ExecuteCommand("Edit.ClearOutputWindow", "");
            Marshal.ReleaseComObject(ide);
        }
    }
    #endregion

'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM