WindowVisibilityEventsClass.WindowHiding 事件

此 API 支持 .NET Framework 基础结构,不适合在代码中直接使用。

窗口隐藏时调用。

命名空间:  EnvDTE80
程序集:  EnvDTE80(在 EnvDTE80.dll 中)

语法

声明
Public Overridable Event WindowHiding As _dispWindowVisibilityEvents_WindowHidingEventHandler
public virtual event _dispWindowVisibilityEvents_WindowHidingEventHandler WindowHiding
public:
virtual   event _dispWindowVisibilityEvents_WindowHidingEventHandler^ WindowHiding {
    void add (_dispWindowVisibilityEvents_WindowHidingEventHandler^ value);
    void remove (_dispWindowVisibilityEvents_WindowHidingEventHandler^ value);
}
abstract WindowHiding : IEvent<_dispWindowVisibilityEvents_WindowHidingEventHandler,
    EventArgs>
override WindowHiding : IEvent<_dispWindowVisibilityEvents_WindowHidingEventHandler,
    EventArgs>
JScript 不支持事件。

实现

_dispWindowVisibilityEvents_Event.WindowHiding

备注

单击框架右上角中的“x”时会隐藏窗口。

示例

此示例使用一个外接程序来连接 WindowVisibilityEvents。 将 Connect.vb 或 Connect.cs 文件中的代码替换为下面的代码示例。 运行此外接程序,并在 Visual Studio IDE 中打开并关闭**“命令窗口”“输出窗口”**以查看正在执行的事件捕获方法。 有关如何运行自动化示例的更多信息,请参见 如何:编译和运行自动化对象模型代码示例

Imports System
Imports Microsoft.VisualStudio.CommandBars
Imports Extensibility
Imports EnvDTE
Imports EnvDTE80

Public Class Connect
    Implements IDTExtensibility2
    Dim applicationObject As DTE2
    Dim addInInstance As AddIn
    Public WithEvents windowsVisEvents As EnvDTE80.WindowVisibilityEvents
    Public Sub New()
    End Sub
    Public Sub OnConnection(ByVal application As Object, _
 ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, _
 ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    applicationObject = CType(application, DTE2)
    addInInstance = CType(addInInst, AddIn)
    Dim toolwin As EnvDTE80.ToolWindows
    toolwin = applicationObject.ToolWindows
    windowsVisEvents = CType(toolwin.DTE.Events, _
    Events2).WindowVisibilityEvents
End Sub
Private Sub windowsVisEvents_WindowHiding(ByVal Window As _
 EnvDTE.Window) Handles windowsVisEvents.WindowHiding
    MsgBox(Window.Caption & " is hiding.")
End Sub
Private Sub windowsVisEvents_WindowShowing(ByVal Window As _
 EnvDTE.Window) Handles windowsVisEvents.WindowShowing
    MsgBox(Window.Caption & " is showing.")
End Sub
Public Sub OnDisconnection(ByVal disconnectMode _
 As ext_DisconnectMode, ByRef custom As Array) Implements  _
IDTExtensibility2.OnDisconnection
    windowsVisEvents = Nothing
End Sub
Public Sub OnAddInsUpdate(ByRef custom As Array) Implements _
 IDTExtensibility2.OnAddInsUpdate
End Sub
Public Sub OnStartupComplete(ByRef custom As Array) Implements _
 IDTExtensibility2.OnStartupComplete
End Sub
Public Sub OnBeginShutdown(ByRef custom As Array) Implements _
 IDTExtensibility2.OnBeginShutdown
End Sub
End Class
[C#]
namespace CS_Events_Code
{
using System;
using Microsoft.VisualStudio.CommandBars;
using Extensibility;
using EnvDTE;
using EnvDTE80;
using System.Windows.Forms;
  public class Connect : Object, IDTExtensibility2
  {
   public Connect()
   {
   }
   public void OnConnection(object application, ext_ConnectMode
 connectMode, object addInInst, ref Array custom)
    {
    applicationObject = (DTE2)application;
    addInInstance = (AddIn)addInInst;
    EnvDTE80.Events2 events = (EnvDTE80.Events2
 )applicationObject.Events;
    windowsVisEvents = 
(EnvDTE80.WindowVisibilityEvents)events.get_WindowVisibilityEvents
(null);
    // Connect to each delegate exposed from the windows visibiliy 
    // events object retrieved above
    windowsVisEvents.WindowHiding +=new 
_dispWindowVisibilityEvents_WindowHidingEventHandler
(this.WindowHiding); 
    windowsVisEvents.WindowShowing +=new 
_dispWindowVisibilityEvents_WindowShowingEventHandler
(this.WindowShowing);
   }
   public void OnDisconnection(ext_DisconnectMode disconnectMode,
 ref Array custom)
   {
    if (windowsVisEvents != null)
    {
        windowsVisEvents.WindowHiding -= new 
_dispWindowVisibilityEvents_WindowHidingEventHandler
(this.WindowHiding);
       windowsVisEvents.WindowShowing -= new 
_dispWindowVisibilityEvents_WindowShowingEventHandler
(this.WindowShowing);
   }
   }
   public void OnAddInsUpdate(ref Array custom)
   {
   }
public void OnStartupComplete(ref Array custom)
   {
   }
public void OnBeginShutdown(ref Array custom)
   {
   }
private DTE2 applicationObject;
private AddIn addInInstance;
private EnvDTE80.WindowVisibilityEvents windowsVisEvents;
public void WindowHiding(EnvDTE.Window winRef)
   {
    MessageBox.Show("The window " + winRef.Caption + " is hiding.");
   }
public void WindowShowing(EnvDTE.Window winRef)
   {
    MessageBox.Show("The window " + winRef.Caption + " is showing.");
   }
  }
}

.NET Framework 安全性

请参阅

参考

WindowVisibilityEventsClass 类

EnvDTE80 命名空间