I am writing a user control which contains a some child controls (all
TextBox controls).

When the user control is loaded, I could set it as focused, but non of it's
child controls is focused. THen I could click on one of the child controls
to make it focused. After that I try to set the focus back from the child
contrl to is parent, theUserControl.Focus() always return false.

Does anyone know how to do it?

Thanks a lot
Mike

Re: HELP !!! Focus() always return false if a child control is Focused already by Stoitcho

Stoitcho
Mon Apr 04 19:53:05 CDT 2005

Mike,

Focus() returns *false* because the user control never get focused. As soon
as you call Focus() on the user control it throws the focuse over one of its
children. If you want the user control to receive the focus the easiest way
is to set TabStop properties for all its children to *false* this way it
won't transfer the focus.
Alternatively if you want just to remove the focuse from the text boxes you
can set user control's ActiveControl property to *null*. This will remove
the focus from the text boxes.


HTH
Stoitcho Goutsev (100) [C# MVP]

"Mike Zhang" <mike_zh@hotmail.com> wrote in message
news:u4LGA0WOFHA.508@TK2MSFTNGP12.phx.gbl...
>I am writing a user control which contains a some child controls (all
> TextBox controls).
>
> When the user control is loaded, I could set it as focused, but non of
> it's
> child controls is focused. THen I could click on one of the child controls
> to make it focused. After that I try to set the focus back from the child
> contrl to is parent, theUserControl.Focus() always return false.
>
> Does anyone know how to do it?
>
> Thanks a lot
> Mike
>
>



Re: HELP !!! Focus() always return false if a child control is Focused already by Mike

Mike
Tue Apr 05 11:51:55 CDT 2005

Stoitcho,

Your solutions works great.
Thanks a lot !!!
Mike
"Stoitcho Goutsev (100) [C# MVP]" <100@100.com> wrote in message
news:us5NUnXOFHA.164@TK2MSFTNGP12.phx.gbl...
> Mike,
>
> Focus() returns *false* because the user control never get focused. As
soon
> as you call Focus() on the user control it throws the focuse over one of
its
> children. If you want the user control to receive the focus the easiest
way
> is to set TabStop properties for all its children to *false* this way it
> won't transfer the focus.
> Alternatively if you want just to remove the focuse from the text boxes
you
> can set user control's ActiveControl property to *null*. This will remove
> the focus from the text boxes.
>
>
> HTH
> Stoitcho Goutsev (100) [C# MVP]
>
> "Mike Zhang" <mike_zh@hotmail.com> wrote in message
> news:u4LGA0WOFHA.508@TK2MSFTNGP12.phx.gbl...
> >I am writing a user control which contains a some child controls (all
> > TextBox controls).
> >
> > When the user control is loaded, I could set it as focused, but non of
> > it's
> > child controls is focused. THen I could click on one of the child
controls
> > to make it focused. After that I try to set the focus back from the
child
> > contrl to is parent, theUserControl.Focus() always return false.
> >
> > Does anyone know how to do it?
> >
> > Thanks a lot
> > Mike
> >
> >
>
>