gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 21:39:59 24 4
gpt4 key购买 nike

对于 VS 2012,我无法使用以下 MSDN code 清除调试器输出窗口,

基本上我无法将 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。

Is it possible to programmatically clear the Ouput Window in Visual Studio?

Can the Visual Studio (debug) Output window be programatically cleared?

最佳答案

我是这样实现的。请注意对另一个对我有帮助的问答的引用。

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

'

关于c# - 如何清除调试器输出窗口 Visual Studio 2012,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17095975/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com