adapter information

Ask general questions here.
mander95
Posts: 58
Joined: Tue Jun 21, 2016 7:35 pm

adapter information

Post by mander95 » Thu Jun 30, 2016 10:26 pm

I'm trying to make a function that outputs the coordinates of the center of a repository item given that repository item (repo.blah for example), please help

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: adapter information

Post by odklizec » Fri Jul 01, 2016 7:26 am

Hi,

I believe you are looking for a code like this:

Code: Select all

int xVal=repo.blah.Element.Location.X;
int yVal=repo.blah.Element.Location.Y;
int widthVal = repo.blah.Element.Size.Width/2;
int heightVal = repo.blah.Element.Size.Heigh/2;
int repoCenterXVal= xVal + widthVal;
int repoCenterYVal= yVal + heightVal;
This code returns center x/y position of a given repo element, based of its client rectangle coordinates/size. If you want screen rectangle-based position, replace 'Location' keyword with 'ScreenLocation' keyword. Hope this helps? ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: adapter information

Post by Support Team » Fri Jul 01, 2016 7:38 am

There's also an alternative using the Ranorex API, so you don't have to do all the math yourself:
System.Drawing.Point screenLocation = Ranorex.Location.Center.GetScreenLocation(element);
You can use any location (e.g. a custom one or even one including an image search) instead of the "Center" and there is also a GetElementLocation method in the Location class in case you don't want screen but relative coordinates.

Regards,
Alex
Ranorex Team

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: adapter information

Post by odklizec » Fri Jul 01, 2016 7:46 am

Thanks for the info Alex, that's definitely a useful tip! ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

mander95
Posts: 58
Joined: Tue Jun 21, 2016 7:35 pm

Re: adapter information

Post by mander95 » Fri Jul 01, 2016 8:14 pm

thank you