Visual Studio 1

This sample works with both Visual Studio 2003 and Visual Studio 2005.

The RanorexVS2005Sample1 illustrates how to use Ranorex from a simple Visual Studio C# console application.
The sample shows how to create a new Visual Studio C# console application and how to start and automate a simple windows GUI application with RanorexNet.

Create, build and run the sample

Start Microsoft Visual Studio, from the 'File' menu click 'New Project' and select a 'Console Application'.
Right-click the 'References' folder within the projects 'Solution Explorer' and open the 'Add Reference' dialog. Browse for the 'RanorexNet.dll' within the Ranorex installation path.
'RanorexNet' is added to the 'References' folder. Important: Also make sure that 'RanorexCore.dll' and 'RanorexSpy.dll' exist at your project output path. Please setup the build options of your project under 'Project' | 'Properties' | 'Configuration Properties' | 'Build' | 'Output Path'.
Open the file 'Program.cs'.
Add following code line to your existing using section.
C#
using Ranorex;
Mark the main thread with the attribute [STAThread]
C#
[STAThread]
static int Main(string[] args)
We use COM in RanorexCore and COM Interop in RanorexNet, so we need a SingleThreadedAppartement.
If you create a WindowsApplication, Visual Studio creates this attribute for you automatically.

Add the following code lines to the 'main' routine of the class 'Program':
C#
Console.WriteLine("Start Ranorex VS2005 sample1");
//----------------------------------------------------------------- 
// F O R M   search and test, Activate = true, Timeout = 5000 msec 
//----------------------------------------------------------------- 
Form form = Application. FindFormClassName ("SciCalc");
if ( form == null )
{
	Console.WriteLine("Start tested application");
	Application.Start("calc.exe");
	form = Application. FindFormClassName ("SciCalc",1, true ,5000);
	if ( form == null )
	{
		Console .WriteLine("Application \"calc.exe\" not found"); 
		return -1;
	}
}
 
Console .WriteLine("Searching and testing button1"); 
Control button1= form.FindChildText("1");
if ( button1 == null )
{
	Console.WriteLine("ERROR: button1 not found ");
	return -1;
}
if ( Mouse.ClickControl(button1) != 0 )
{
	Console.WriteLine("ERROR: pressing button1");
	return -1;           
}
 
Console .WriteLine("Searching and testing button9"); 
Control button9 = form.FindChildText("9");
if ( button9 == null )
{
	Console.WriteLine("ERROR: button9 not found ");
	return -1;
}
if ( Mouse.ClickControl(button9) != 0 )
{
	Console.WriteLine("ERROR: pressing button9");
	return -1;           
}		
 
Console.WriteLine("Closing application"); 
Application.Sleep(2000); 
form.Close(); 
return 0;