| View previous topic :: View next topic |
| Author |
Message |
Chrispy
Joined: 25 Mar 2008 Posts: 5
|
Posted: Wed Mar 26, 2008 1:35 pm Post subject: Trying to get the .Pressed to work for a button - help? |
|
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: click into code to enlarge
//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.
| Quote: |
| 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. |
|
| Back to top |
|
 |
Support Team Site Admin
Joined: 07 Jul 2006 Posts: 257
|
Posted: Wed Mar 26, 2008 2:42 pm Post subject: |
|
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 |
|
| Back to top |
|
 |
Chrispy
Joined: 25 Mar 2008 Posts: 5
|
Posted: Wed Mar 26, 2008 3:40 pm Post subject: |
|
So how would I be able to click a button and retrieve the current state?
Any advise would be very helpfull. |
|
| Back to top |
|
 |
Support Team Site Admin
Joined: 07 Jul 2006 Posts: 257
|
Posted: Wed Mar 26, 2008 4:11 pm Post subject: |
|
Well, you can use the Mouse.ButtonDown and Mouse.ButtonUp methods:
Code: click into code to enlarge
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 |
|
| Back to top |
|
 |
|