Page 1 of 1

Finding a UserControl

Posted: Wed Mar 11, 2009 11:27 am
by rcd.guerra
Hi there,

we have a large base of custom UserControls embedded in Infragistics DockableWindows. Ranorex is able to track almost everything from the top window container to the docking area displaying the correct Infragistics types.
The issue here is that the embedded UserControl is of type Unknown. Is there a way to get a reference to the control itself, say:

Code: Select all

MyCustomControl c = MyRanoreXPath
and get all of its properties ? Perhaps we should reference our dlls.

I must add that the inner controls of our "MyCustomControl" like textboxes, comboboxes and so on are perfectly recognized. Only the UserControl is not.


Thanks in advance!

Cheers,
Ricardo

Posted: Wed Mar 11, 2009 2:29 pm
by Support Team
Sorry, but you can't access your custom control directly as it resides in another process space. However, if it's a .NET Windows Forms Control, you can use the Control adapter to access properties and methods of your user control.

Code: Select all

// get the Ranorex.Control adapter from an Unknown element in the repository
Unknown customControlOfUnknownType = repo.MyCustomControlOfUnknownType;
Ranorex.Control myCustomControl = customControlOfUnknownType.As<Ranorex.Control>();
// ... or by directly using the path to the custom control
myCustomControl = "pathToMyCustomControl";

// access properties and methods 
object value = myCustomControl.GetPropertyValue("MyProperty");
string stringValue = myCustomControl.GetPropertyValue<string>("MyStringProperty");
object[] args = new object[] { "arg1", 2 };
myCustomControl.InvokeMethod("MyMethod", args);
Please, consider reading the following blog that shows how to access custom Windows Forms controls:
http://www.ranorex.com/blog/transfering ... et-control

Regards,
Alex
Ranorex Support Team

Posted: Thu Mar 12, 2009 10:08 am
by rcd.guerra
Ok Alex.

The example you point out is with a "Control" type. Being the "UserControl" a derived type from "Control" i assume its also possible.
I need to check the example more carefully.

Are you going to support this feature natively in a near future ?

Thanks.

Cheers,
Ricardo

Posted: Thu Mar 12, 2009 12:27 pm
by Support Team
The Control adapter used above is not the same as the System.Windows.Forms.Control. Ranorex.Control is a Ranorex specific class inheriting from Ranorex.Adapter that facilitates accessing System.Windows.Forms.Control instances in other processes by providing methods like Get/SetPropertyValue, InvokeMethod, or InvokeRemotely. However, it is not a System.Windows.Forms.Control itself, as you can't directly access a System.Windows.Forms.Control from another process.

You can use the example above for every element that corresponds to a control derived from System.Windows.Forms.Control.

In one of the next Ranorex versions we want to support System.Windows.Forms.Control properties "natively", i.e. you could then use System.Windows.Forms.Control properties in RanoreXPaths and would see the properties in RanorexSpy.

Regards,
Alex
Ranorex Support Team

Posted: Thu Mar 12, 2009 2:53 pm
by rcd.guerra
Thanks for claryfing!