How to check custom button's .Checked state?

Ask general questions here.
Sergey
Posts: 2
Joined: Fri Sep 11, 2009 11:18 pm

How to check custom button's .Checked state?

Post by Sergey » Fri Sep 11, 2009 11:50 pm

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.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

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

Post by Support Team » Sat Sep 12, 2009 9:52 am

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

Sergey
Posts: 2
Joined: Fri Sep 11, 2009 11:18 pm

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

Post by Sergey » Mon Sep 14, 2009 1:18 pm

Thanks!
That's what it was.... wrong syntax.