Trying to get the .Pressed to work for a button - help? : Automation API

Trying to get the .Pressed to work for a button - help?

Class library usage, coding and language questions.

Trying to get the .Pressed to work for a button - help?

Postby Chrispy » Wed Mar 26, 2008 1:35 pm

I'm get a return when a button has been pressed. I had this working but now fails everytime I try and get the pressed return from calc.

Code: Select all
//Perform click test to see if the button rasies a click event
                Button ClickButton = (Button)form.FindButton(button.ControlId);
                ClickButton.Click();
                Console.WriteLine("BUTTON PRESSED?: " + ClickButton.Pressed);
               


I've tried the example also from your Getting started guide but this is incorrect.

Button button = form.FindButton("button1");
This specifies an error as your trying to specify a string and not an int value.

I'm currently evaluating this and any help with trying to sort it out would be great.
Chrispy
 
Posts: 5
Joined: Tue Mar 25, 2008 2:43 pm

Postby Support Team » Wed Mar 26, 2008 2:42 pm

The Button.Pressed property returns the current state of the button. I.e. if you click the button in the previous line, that does not necessarily mean the button is still pressed.

Chrispy wrote:Button button = form.FindButton("button1");

This is another overload of the Control.FindButton method that searches for .NET Windows Forms controls by their name. As this overload is only useful for .NET Windows Forms controls, you can't use it with the Windows Calculator (though your code should compile anyway).

Regards
Alex
Ranorex Support Team
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Postby Chrispy » Wed Mar 26, 2008 3:40 pm

So how would I be able to click a button and retrieve the current state?

Any advise would be very helpfull.
Chrispy
 
Posts: 5
Joined: Tue Mar 25, 2008 2:43 pm

Postby Support Team » Wed Mar 26, 2008 4:11 pm

Well, you can use the Mouse.ButtonDown and Mouse.ButtonUp methods:
Code: Select all
Mouse.MoveToControl(button);
Mouse.ButtonDown(MouseButtonType.LeftButton);
bool buttonPressed = button.Pressed;
Mouse.ButtonUp(MouseButtonType.LeftButton);

However, if you want to check, whether the button has been clicked, I'd recommend checking if your application has reacted to the click rather than recognizing the click itself.

Alex
Ranorex Support Team
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria


Return to Automation API

Who is online

Users browsing this forum: No registered users and 0 guests

cron