Page 1 of 1

How to check custom button's .Checked state?

Posted: Fri Sep 11, 2009 11:50 pm
by Sergey
Hello,
I created Repository (Ranorex 2.0.1) that contains bunch of buttons, labels, etc.
Some buttons are custom (inherited from System.Windows.Forms.Button) but they also have a "Checked" attribute. Basically it's a check type button that stays de-pressed when you select it.
For some reason I can't verify this state... When I type:

Code: Select all

Button1.
... I don't have the "Checked" option.

I remember that in previous version on Ranorex I could do something like that:

Code: Select all

Ranorex.Control c = (Ranorex.Control)repo.FormTest.Button1;
if (c.GetPropertyValue<bool>("Checked"))
       selection = 1;
... but it doesn't work for me because Ranorex Button cannot be converted to Ranorex Control

Is there any way to add this custom feature to Repository? What's the solution, if any?
Thank you. I love Ranorex and this is the first time I actually ran into a problem in 2.0.1.

Re: How to check custom button's .Checked state?

Posted: Sat Sep 12, 2009 9:52 am
by Support Team
If your custom button has the Control capability (see Ranorex User Guide), then you can create a Control adapter for it:
Ranorex.Control c = new Ranorex.Control(repo.FormTest.Button1);
if (c.GetPropertyValue<bool>("Checked"))
       selection = 1;
I think you tried to do that, just your syntax was wrong. With Ranorex 2.X you don't cast between different adapters, but you create new adapters. An exception will be raised if the element does not provide the capability needed for the adapter. Alternatively, you can use the Adapter.As<Ranorex.Control>() method to create a new adapter and get a null reference back instead of an exception if the creation fails. For more info read the corresponding section in the Ranorex User Guide:
http://www.ranorex.com/support/user-gui ... apter.html

Regards,
Alex
Ranorex Support Team

Re: How to check custom button's .Checked state?

Posted: Mon Sep 14, 2009 1:18 pm
by Sergey
Thanks!
That's what it was.... wrong syntax.