HELP !!! Focus() always return false if a child control is Focused already

  • Thread starter Thread starter Mike Zhang
  • Start date Start date
M

Mike Zhang

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
 
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]
 
Stoitcho,

Your solutions works great.
Thanks a lot !!!
Mike
Stoitcho Goutsev (100) said:
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 said:
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
 
Back
Top