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
Darren Stokes - 06 Dec 2007 01:08 GMT
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
> Hello,
>
[quoted text clipped - 54 lines]
> Thanks in advance
> Alex
Alex Blekhman - 06 Dec 2007 12:44 GMT
> I don't think your control's visibility is actually
> changing. The visibility
[quoted text clipped - 10 lines]
> 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