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.
Thanks in advance,
Re: detecting when UserControl gets focus - 11-14-2008 , 03:15 AM
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,
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)
Re: detecting when UserControl gets focus - 11-14-2008 , 08:30 AM
I was thinking that something like your suggestion might be the best
solution. Thanks for the details and the forum suggestion.
"Cindy M." <C.Meister-C (AT) hispeed (DOT) ch> wrote
|Thread Tools||Search this Thread|