If I add a WindowEvents_WindowActivated
handler to my Visual Studio 2005 Macros EnvironmentEvents
module, I get a weird side-effect: when I click from one window to another in Visual Studio, that click is treated as a double click.
So for instance, I put the focus in an editor window and click a file in Solution Explorer, and the file opens.
Or I put the focus in the Toolbox and click in an editor window, and the word I click on gets selected. In most cases, when a single-click causes a window to activate, that click is being treated as a double-click.
This happens even with an empty event handler:
Private Sub WindowEvents_WindowActivated(ByVal GotFocus As EnvDTE.Window, _
ByVal LostFocus As EnvDTE.Window) _
Handles WindowEvents.WindowActivated
' Do nothing.
End Sub
I want to use the WindowActivated
event to do cool stuff, but this is a killer. Has anyone seen this before and worked around it? (I know I could use a timer and poll for the current window, but yuck.)
I do not have this problem. Most likely the WindowActivated event is being fired twice. This usually happens when another process steals focus, such as another add-in, from the activated window then the window is re-activated. You can duplicate the behavior you are experiencing by adding a MsgBox call within the WindowActivated event.
Edit by RichieHindle: The real answer is buried in the comments: "Have you tried this in an add-in?" It works fine in an add-in.