Form.GetControls

Bug reports.
GuiTester
Posts: 4
Joined: Mon Sep 11, 2006 6:49 am

Form.GetControls

Post by GuiTester » Fri Sep 15, 2006 9:53 am

The class Form has a method called GetControls which does not take any parameter and the return value is also void. The help for the method says "Gets an array containing all controls in the form ."

Also, is there a reason why the classes are named same as in the Systems.Windows? If I use System.Windows.Forms.Form and Ranorex.Form in the same program, I need explicitly specify which form I want to use.

And looking at the code: form.<somemethod> there is no way to tell whether it is systems form or Ranorex form. The code looks very messy.

admin
Site Admin
Site Admin
Posts: 350
Joined: Wed Jul 05, 2006 7:44 pm

Post by admin » Fri Sep 15, 2006 11:35 pm

The Form class function GetControls() makes a connection to the automated form, reads all controls and fills the Form property Controls. For speed reasons the function will not called in the constructor of the Form class. The user must call the GetControls() function to read and fill the control array.

Code: Select all

form.GetControls();
foreach (Control control in form.Controls)
{
    IntPtr handle = control.Handle;
    Point location = control.Location;
    Size size = control.Size;
    String text = control.Text;
    Console.WriteLine("Handle={0} Location={1} Text={2}", handle, location, text);
}
See also the sample project RanorexVS2005Sample4
I’m sorry for the poor documentation, we will extend it with some samples in the next version.

> Why the classes in RanorexNet have the same names as in System.Windows.Forms?
Normally you make a console application if you write testscripts, so you don't use the System.Windows.Forms namespace.
It's easier to write and understand the automation code if you use the same class names as in the real application.

Jenö Herget
Ranorex Team