Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / December 2007

Tip: Looking for answers? Try searching our database.

Control.VisibleChanged event not fired when tool window is closed

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alex Blekhman - 24 Nov 2007 18:31 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.