This example illustrates how to use Ranorex 2 within a simple Visual Studio C# console application. It shows how to create a new Visual Studio C# console application and how to start and automate the Windows Calculator.
Note: The sample works with both Microsoft Visual Studio 2005 and 2008.
Start Microsoft Visual Studio. From the 'File' menu click 'New Project' to open the New Project Dialog. In this example we use C# as programming language. Choose another language if you'd like to implement Ranorex code in VB.NET or Visual C++.
Right-click the 'References' folder within the projects 'Solution Explorer' and open the 'Add Reference' dialog. Select the components “System.Drawing” and “Ranorex Core”.
using System.Drawing; using Ranorex;
Imports System.Drawing Imports Ranorex
[STAThread] static int Main(string[] args)
<STAThread> _ Public Shared Function Main(args As String()) As Integer
int error = 0;
try
{
System.Diagnostics.Process.Start("calc.exe");
Form form = Host.Local.FindChild<Ranorex.Form>("Calculator");
form.Activate();
Button button = form.FindChild<Ranorex.Button>("2");
button.Click();
button = form.FindChild<Ranorex.Button>("*");
button.Click();
button = form.FindChild<Ranorex.Button>("3");
button.Click();
button = form.FindChild<Ranorex.Button>("=");
button.Click();
}
catch (RanorexException e)
{
Console.WriteLine(e.ToString());
error = -1;
}
return error;
Dim returnError As Integer = 0
Try
System.Diagnostics.Process.Start("calc.exe")
Dim form As Form = Host.Local.FindChild(Of Ranorex.Form)("Calculator")
form.Activate()
Dim button As Button = form.FindChild(Of Ranorex.Button)("2")
button.Click()
button = form.FindChild(Of Ranorex.Button)("*")
button.Click()
button = form.FindChild(Of Ranorex.Button)("3")
button.Click()
button = form.FindChild(Of Ranorex.Button)("=")
button.Click()
Catch e As RanorexException
Console.WriteLine(e.ToString())
returnError = -1
End Try
Return returnError
Online User Guide
download as: PDF (20.3MB)
Ranorex Tutorial
(PDF file, 13.5MB)
