Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
tools
vsnet.act
vsnet.debugging
vsnet.documentation
vsnet.enterprise.tools
vsnet.general
vsnet.ide
vsnet.jlca
vsnet.servicepacks
vsnet.setup
vsnet.vsip
vsnet.vss
vsnet.vstools.office
vstudio.development
vstudio.extensibility
vstudio.general
vstudio.helpauthoring
vstudio.setup
vstudio.sourcesafe
  
 
date: Sat, 24 Nov 2007 20:31:12 +0200,    group: microsoft.public.vstudio.extensibility        back       


Control.VisibleChanged event not fired when tool window is closed   
Hello,

I have C# add-in for VS2005. From this add-in I create tool
window (see code in my previous post).

I try to handle `Control.VisibleChanged' event:

// MyAddInCtrl.cs

public partial class MyAddInCtrl : UserControl
{
    public MyAddInCtrl()
    {
        InitializeComponent();
    }

    private void MyAddInCtrl_VisibleChanged(
        object sender, EventArgs e)
    {
        if (this.Visible)
        {
            // do something
        }
    }
}

// MyAddInCtrl.Designer.cs

partial class MyAddInCtrl
{
    private void InitializeComponent()
    {
        ...

        this.VisibleChanged +=
            new System.EventHandler(
                this.MyAddInCtrl_VisibleChanged);

        ...
    }
}

However, `MyAddInCtrl_VisibleChanged' handler called only 
twice: when user select menu command for my add-in for the 
fist time (and `_MyAddInWnd.Visible' set to `true' for the 
fist time, respectively); and when IDE is closed and the 
add-in is unloaded.

If I click the tool window's close button, then the window 
disappears, but `MyAddInCtrl_VisibleChanged' is not called. 
Subsequent calls "_MyAddInWnd.Visible = true;" from 
`Connect.Exec' show the tool window back, but handler is not 
called either.

How can I handle visibility changes for my tool window?

Thanks in advance
Alex
date: Sat, 24 Nov 2007 20:31:12 +0200   author:   Alex Blekhman

RE: Control.VisibleChanged event not fired when tool window is closed   
I don't think your control's visibility is actually changing.  The visibility 
of the window containing it is changing.  I think you might need to handle 
the closing event of the window by attaching an event handler to the window 
returned from CreateToolWindow2.  Something like the following might work for 
you:

EnvDTE.Window win = window2.CreateToolWindow2(....);
WindowEvents we = ((DTE2) win.DTE).Events.get_WindowEvents(win);
we.Window.Close+= ....

Hope this helps.

-Darren


"Alex Blekhman" wrote:

> Hello,
> 
> I have C# add-in for VS2005. From this add-in I create tool
> window (see code in my previous post).
> 
> I try to handle `Control.VisibleChanged' event:
> 
> // MyAddInCtrl.cs
> 
> public partial class MyAddInCtrl : UserControl
> {
>     public MyAddInCtrl()
>     {
>         InitializeComponent();
>     }
> 
>     private void MyAddInCtrl_VisibleChanged(
>         object sender, EventArgs e)
>     {
>         if (this.Visible)
>         {
>             // do something
>         }
>     }
> }
> 
> // MyAddInCtrl.Designer.cs
> 
> partial class MyAddInCtrl
> {
>     private void InitializeComponent()
>     {
>         ...
> 
>         this.VisibleChanged +=
>             new System.EventHandler(
>                 this.MyAddInCtrl_VisibleChanged);
> 
>         ...
>     }
> }
> 
> However, `MyAddInCtrl_VisibleChanged' handler called only 
> twice: when user select menu command for my add-in for the 
> fist time (and `_MyAddInWnd.Visible' set to `true' for the 
> fist time, respectively); and when IDE is closed and the 
> add-in is unloaded.
> 
> If I click the tool window's close button, then the window 
> disappears, but `MyAddInCtrl_VisibleChanged' is not called. 
> Subsequent calls "_MyAddInWnd.Visible = true;" from 
> `Connect.Exec' show the tool window back, but handler is not 
> called either.
> 
> How can I handle visibility changes for my tool window?
> 
> Thanks in advance
> Alex 
> 
> 
>
date: Wed, 5 Dec 2007 17:08:01 -0800   author:   Darren Stokes

Re: Control.VisibleChanged event not fired when tool window is closed   
"Darren Stokes" wrote:
> I don't think your control's visibility is actually 
> changing.  The visibility
> of the window containing it is changing.  I think you 
> might need to handle
> the closing event of the window by attaching an event 
> handler to the window
> returned from CreateToolWindow2.  Something like the 
> following might work for
> you:
>
> EnvDTE.Window win = window2.CreateToolWindow2(....);
> WindowEvents we = ((DTE2) 
> win.DTE).Events.get_WindowEvents(win);
> we.Window.Close+= ....

Thanks for the answer. Yes, tool window visibility is more 
like creation, actually. In the end I redesigned my add-in 
so it won't rely on window's visibility at all.

Alex
date: Thu, 6 Dec 2007 14:44:58 +0200   author:   Alex Blekhman

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us