簡體   English   中英

如何清除調試器輸出窗口Visual Studio 2012

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

對於VS 2012,我無法使用以下MSDN代碼清除調試器輸出窗口,

基本上我無法將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();
}

使用其他SO鏈接無法使其適用於VS2012。

是否可以以編程方式清除Visual Studio中的輸出窗口?

可以以編程方式清除Visual Studio(調試)輸出窗口嗎?

這是我實現它的方式。 請注意對另一個幫助我的問題的答案。

'   #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