Page 1 of 1

Currently focused control

Posted: Tue Jan 26, 2016 10:22 am
by BCTest
I found this simple code in this forum to access the currently activated window:
//Search for the active foreground window and checks if "active" state is true
Ranorex.Form myActiveForm = Host.Local.FindSingle("/form[@active='True']");
Is it possible to access the currently focused control in this Form?
It could be a button, an edit-control, a combobox or whatever...

Regards,
Thomas

Re: Currently focused control

Posted: Tue Jan 26, 2016 10:49 am
by odklizec
Hi,

Try something like this...
Ranorex.Form myActiveForm = Host.Local.FindSingle("/form[@active='True']/*[@accessiblestate~'Focused']");
This should return first focused element on active form.

Re: Currently focused control

Posted: Tue Jan 26, 2016 11:44 am
by BCTest
odklizec wrote:Hi,

Try something like this...
Ranorex.Form myActiveForm = Host.Local.FindSingle("/form[@active='True']/*[@accessiblestate~'Focused']");
This should return first focused element on active form.
Hello odklizec,

Thanks for your fast and proper answer: exactly what I want!
Ranorex.Core.Element activeElement = Host.Local.FindSingle("/form[@active='True']/*[@accessiblestate~'Focused']");
Regards,
Thomas

Re: Currently focused control

Posted: Tue Jan 26, 2016 12:30 pm
by odklizec
Cool. I'm glad I could help ;)