Page 1 of 1

Working with Checkbox style buttons (C#)

Posted: Tue Nov 11, 2008 2:36 pm
by bebenin_s
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.

Posted: Tue Nov 11, 2008 3:30 pm
by Support Team
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

Posted: Tue Nov 11, 2008 5:25 pm
by bebenin_s
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]

Posted: Tue Nov 11, 2008 6:14 pm
by Support Team
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");

Posted: Tue Nov 11, 2008 7:34 pm
by bebenin_s
Awesome! It worked, I really appreciate it!