
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. Also add the 'System.Drawing' library from the '.Net' tab.


using System.Drawing; using Ranorex;
[STAThread] static int Main(string[] args)
Application.SleepTime = 100; Mouse.MoveTime = 400; String startApplication = "VS2005Application"; if ( args.Length>1 && args[0] == "-a" ) startApplication = args[1]; //------------------------------------------------------------------------------------- // F O R M search and test //------------------------------------------------------------------------------------- Form form = Application.FindFormTitle("RanorexTestedApp"); if ( form == null ) { Console.WriteLine("Start {0}",startApplication); Application.Start(startApplication); form = Application.FindFormTitle("RanorexTestedApp",SearchMatchMode.MatchExact,true,5000); if ( form == null ) { Console .WriteLine("ERROR: starting application \"{0}\"", startApplication); return -1; } } Console.WriteLine("Application found"); //------------------------------------------------------------------------------------- // Print location and size of the form //------------------------------------------------------------------------------------- Point location = form.Location; Console.WriteLine("Form location X={0} Y={1}", location.X, location.Y); Size size = form.Size; Console.WriteLine("Form size Width={0} Height={1}\n", size.Width, size.Height); //------------------------------------------------------------------------------------- // B U T T O N Test //------------------------------------------------------------------------------------- Button button = form.FindButton("button1"); if ( button == null ) { Console.WriteLine("ERROR: button1 not found "); return -1; } Console.WriteLine("Button \"button1\" found"); // Move the mouse to the control //Mouse.MoveToControl(button); Mouse.MoveToElement(button.Element); button.Focus(); location = button.Location; size = button.Size; string text = button.Text; Console.WriteLine(" Location X={0} Y={1}", location.X, location.Y); Console.WriteLine(" Width={0} Height={1}", size.Width, size.Height); Console.WriteLine(" Text={0}", text); Console.WriteLine(" Button hide"); button.Hide(); bool visible = button.Visible; Console.WriteLine(" Visible flag = {0}", visible); Console.WriteLine(" Button show"); button.Show(); visible = button.Visible; Console.WriteLine(" Visible flag = {0}", visible); Console.WriteLine(" Click the button"); button.Click(); //Console.WriteLine("\nPress any key to exit the application"); //string inText = Console.ReadLine(); Console .WriteLine("Closing application"); Application .Sleep(2000); form. Close (); Console.WriteLine("\nTEST PASSED\n"); return 0;
Important: Make sure that 'RanorexCore.dll' and 'RanorexSpy.dll' exist at your project output path:
Setup you project settings by selecting the menu item 'Project' | 'Properties'.
Open the 'Build' tab and set the 'Output Path' to the installation path of Ranorex ('bin' directory):