Working with Checkbox style buttons (C#)

Ask general questions here.
bebenin_s
Posts: 6
Joined: Sat Nov 08, 2008 11:43 pm
Location: Boston, MA

Working with Checkbox style buttons (C#)

Post by bebenin_s » Tue Nov 11, 2008 2:36 pm

Hello,
I have a form with Checkbox style buttons. Is there a way to find this specific kind of button?

When I am using:
m_MessageBox = Application.FindFormTitle(formName);
m_ButtonLeft = m_MessageBox.FindButton("btnLeft");

m_ButtonLeft does not have a .Checked attribute. I basically want to see if the button is checked or not checked and then do something based on that state.

Thank you for all your help.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Tue Nov 11, 2008 3:30 pm

Hello bebenin_s,
i think you mean "Windows.Forms.Checkbox" with "Apperiance.Button" style?

If so, you can use the "Ranorex.CheckBox" class instead.


m_MessageBox = Application.FindFormTitle(formName);
m_CheckBox = m_MessageBox.FindCheckBox("btnLeft");

bool isChecked = checkBox.Checked;

Regards,
Chris
Ranorex Support Team

bebenin_s
Posts: 6
Joined: Sat Nov 08, 2008 11:43 pm
Location: Boston, MA

Post by bebenin_s » Tue Nov 11, 2008 5:25 pm

Thanks!
Your suggestion did not work, but I think it's probably because this button has custom properties. After it didn't work, I opened the developers project and found that there is a custom button class that contains a Checked() method.
So I guess Ranorex doesn't pick up Misc properties of the button. Am I correct? When I use RanorexSpyPro to probe this button, there is a Misc section that contains:
Style = Checkbox
Checked = True
Both of these attributes are in this custom button class.

Is there any other way I can check the state of the button besides using the Tool Tips (since they are different)?
Thanks again![/img]

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Tue Nov 11, 2008 6:14 pm

Is your custom button a .net control(windows forms)?

If so, you can get the "Checked" property with the GetPropertyValue function.


// get control z.b. with findControlId()
Control button1 = form.FindControlId(...); (check with RanorexSpyPro)

bool isChecked = button1.GetPropertyValue<bool>("Checked");

bebenin_s
Posts: 6
Joined: Sat Nov 08, 2008 11:43 pm
Location: Boston, MA

Post by bebenin_s » Tue Nov 11, 2008 7:34 pm

Awesome! It worked, I really appreciate it!