Finding a UserControl

Ask general questions here.
rcd.guerra
Posts: 29
Joined: Tue Mar 03, 2009 11:43 pm

Finding a UserControl

Post by rcd.guerra » Wed Mar 11, 2009 11:27 am

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

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Wed Mar 11, 2009 2:29 pm

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
Last edited by Support Team on Thu Mar 12, 2009 11:02 am, edited 1 time in total.

rcd.guerra
Posts: 29
Joined: Tue Mar 03, 2009 11:43 pm

Post by rcd.guerra » Thu Mar 12, 2009 10:08 am

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

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Thu Mar 12, 2009 12:27 pm

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

rcd.guerra
Posts: 29
Joined: Tue Mar 03, 2009 11:43 pm

Post by rcd.guerra » Thu Mar 12, 2009 2:53 pm

Thanks for claryfing!