Hi,

I have Windows Form with several User Controls embedded within. Only one
user control is visible at any one time. The user moves through the various
user controls by clicking Previous and Next buttons. What I want to happen
is for the individual user controls to have the ability to set focus to a
specific textbox control when the user control becomes active. Normally I
would handle this sort of thing via a form's activate event, but user
controls do not have this equivalent I've tried the GotFocus and Enter
events as well but neither fires independently simply when the user control
becomes the form's focus.

Right now I have the textbox focus working - but only through calling it via
the parent form (the parent form causes the user control to come to the
forefront, then sets the focus). But I'd rather have the logic self
contained within the user control. Is there some sort of Activate event
equivilent for user controls?

Thanks

Re: Activate Event Equivilent for UserControl? by Steve

Steve
Thu May 08 09:47:18 CDT 2008

CGatto wrote:
> Hi,
>
> I have Windows Form with several User Controls embedded within. Only
> one user control is visible at any one time. The user moves through
> the various user controls by clicking Previous and Next buttons. What I want
> to happen is for the individual user controls to have the
> ability to set focus to a specific textbox control when the user
> control becomes active. Normally I would handle this sort of thing
> via a form's activate event, but user controls do not have this
> equivalent I've tried the GotFocus and Enter events as well but
> neither fires independently simply when the user control becomes the
> form's focus.

Did you try the EnterFocus event? It seems to work for me...



Re: Activate Event Equivilent for UserControl? by Armin

Armin
Thu May 08 09:25:32 CDT 2008

"CGatto" <cgatto@pleaseremoveme.gnb.ca> schrieb
> Hi,
>
> I have Windows Form with several User Controls embedded within. Only
> one user control is visible at any one time. The user moves
> through the various user controls by clicking Previous and Next
> buttons. What I want to happen is for the individual user controls
> to have the ability to set focus to a specific textbox control when
> the user control becomes active. Normally I would handle this sort
> of thing via a form's activate event, but user controls do not have
> this equivalent I've tried the GotFocus and Enter events as well
> but neither fires independently simply when the user control becomes
> the form's focus.
>
> Right now I have the textbox focus working - but only through
> calling it via the parent form (the parent form causes the user
> control to come to the forefront, then sets the focus). But I'd
> rather have the logic self contained within the user control. Is
> there some sort of Activate event equivilent for user controls?

Good question for the appropriate m.p.d.framework.* group (because it's
not a VB language specific issue). Nevertheless, maybe I've missed
something, but is there a reason why you don't set the Tabindex property
of the control to get the focus to zero? When showing a Usercontrol (in
the button's click event), just call TheUC.Focus in addition (what you
have to do anyway).

I would not write the UC in that way that it automatically claims the
focus when becoming visible because that should be done by the container
(Form) if wanted. I read your question that you only don't want to set
the focus to the first control inside the UC, but that's automatically
done by setting Tabindex=0.


Armin