469,950 Members | 1,881 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

How to detect which control in a form got forcus

There are several controls in my form. How to detect currently which control
has the forcus and set the forcus to a certain control?

Thanks,
Sep 20 '06 #1
1 1801
Gary,

Check the form's ActiveControl property. It will give you the focused
control. Set the propery to change the focus.

This propery is defined in the the IContianerControl interface. That means
if your form has a control that implements this interface and this control
contains the focused control the form's ActiveControl will return reference
to the container (not to the actually focused
control). Thus what you need to do is to check wheter the control in the
ActiveControl property implements IContainerControl and if so get its
ActiveControl propery and so on. Most used controls that implement this
interface are Form, UserControl and the SplitContainer. There are couple
more, but I suggest to check the docs for that.

When you want to change the focused control though, you can do it on any
level of the contianer control hierarchy. The propery setter will take care
of updating the actuall container.

Most used conteiner controls are Form and UserControl.

"Gary" <Ga**@discussions.microsoft.comwrote in message
news:C6**********************************@microsof t.com...
There are several controls in my form. How to detect currently which
control
has the forcus and set the forcus to a certain control?

Thanks,

Sep 20 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Keith Wilby | last post: by
3 posts views Thread by Kubik | last post: by
1 post views Thread by Ludovic Lemarinel | last post: by
7 posts views Thread by kkk | last post: by
1 post views Thread by Gary | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.