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

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
 
S

Stoitcho Goutsev \(100\) [C# MVP]

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]
 
M

Mike Zhang

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top