HighTechTalks DotNet Forums  

detecting when UserControl gets focus

Visual Studio.net (Tools Office) microsoft.public.vsnet.vstools.office


Discuss detecting when UserControl gets focus in the Visual Studio.net (Tools Office) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Doug Glancy
 
Posts: n/a

Default detecting when UserControl gets focus - 11-08-2008 , 01:04 PM






I've created a custom task pane on a User Control using VSTO and VS.Net
2008. In the UserControl I want to detect when focus switches back and
forth between the worksheet and the User Control. I've looked at the
GotFocus, Enter and other events for the User Control, but they don't
capture this change of focus. If it was a dll form, I know I'd use the
Activate event, but that doesn't exist for the User Control.

Any advice?

Thanks in advance,

Doug



Reply With Quote
  #2  
Old   
Cindy M.
 
Posts: n/a

Default Re: detecting when UserControl gets focus - 11-14-2008 , 03:15 AM






Hi Doug,

Quote:
I've created a custom task pane on a User Control using VSTO and VS.Net
2008. In the UserControl I want to detect when focus switches back and
forth between the worksheet and the User Control. I've looked at the
GotFocus, Enter and other events for the User Control, but they don't
capture this change of focus. If it was a dll form, I know I'd use the
Activate event, but that doesn't exist for the User Control.

You may want to go with this to the VSTO forum, as there's more support
there.
http://social.msdn.microsoft.com/Forums/en-US/vsto/threads/#page:1

The problem seems to lie with how the user control is wrapped into the
CTP. The CTP is a type of Office CommandBar. VSTO wraps the user control
into a managed code ActiveX control that, in turn, is enabled for COM. So
not all the properties and events are exposed in the same way.

If I click from the document into a textbox control on the UC the Enter
event is triggered the first time. If I then TAB out of the textbox and
there is no other target in the UC, the leave event will trigger (and the
focus is in the document). If I click into the document, no event in the
UC is triggered, but I do get the event for selection change.

So I guess the best you could do is create events for the controls in the
UC and also trap the event that triggers when the user clicks on the
document. In the "enter" events of the UC set a class-level variable that
records that the UC has gotten the focus. Check this in the document's
selection change event; if it's true you know the UC has been entered,
then left.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)



Reply With Quote
  #3  
Old   
Doug Glancy
 
Posts: n/a

Default Re: detecting when UserControl gets focus - 11-14-2008 , 08:30 AM



Cindy,

I was thinking that something like your suggestion might be the best
solution. Thanks for the details and the forum suggestion.

Doug

"Cindy M." <C.Meister-C (AT) hispeed (DOT) ch> wrote

Quote:
Hi Doug,

I've created a custom task pane on a User Control using VSTO and VS.Net
2008. In the UserControl I want to detect when focus switches back and
forth between the worksheet and the User Control. I've looked at the
GotFocus, Enter and other events for the User Control, but they don't
capture this change of focus. If it was a dll form, I know I'd use the
Activate event, but that doesn't exist for the User Control.

You may want to go with this to the VSTO forum, as there's more support
there.
http://social.msdn.microsoft.com/Forums/en-US/vsto/threads/#page:1

The problem seems to lie with how the user control is wrapped into the
CTP. The CTP is a type of Office CommandBar. VSTO wraps the user control
into a managed code ActiveX control that, in turn, is enabled for COM. So
not all the properties and events are exposed in the same way.

If I click from the document into a textbox control on the UC the Enter
event is triggered the first time. If I then TAB out of the textbox and
there is no other target in the UC, the leave event will trigger (and the
focus is in the document). If I click into the document, no event in the
UC is triggered, but I do get the event for selection change.

So I guess the best you could do is create events for the controls in the
UC and also trap the event that triggers when the user clicks on the
document. In the "enter" events of the UC set a class-level variable that
records that the UC has gotten the focus. Check this in the document's
selection change event; if it's true you know the UC has been entered,
then left.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.