Link to home
Start Free TrialLog in
Avatar of romiebehunin
romiebehunin

asked on

Find position to a control on an external windows form vb.net

Hey guys... I have a set of fields I need to be able to click and set focus to in an external window. Historically I've been able to do this by providing x, y locations to various controls and sending a mouse click to that coordinate. In this particular case the x, y locations could vary due to different monitor types, resolutions, DPI etc.

If I could find a way to find out the controls exact x,y coordinates programatically that would really help my delima. I've seen some examples on how one might accomplish this via c# but I'm not sure how to tackle it in VB.NET.

I've been doing some reading about using PointToScreen and PointToClient but those are within 'control' objects. I have the windows handles of the controls I'm interested in but I'm not sure how to use that handle and create a control object. Any help (kick in the right direction) would be greatly appreciated.
Avatar of unknown_routine
unknown_routine
Flag of United States of America image

I've been able to do this by providing x, y locations to various controls and sending a mouse click to that coordinate. In this particular case the x, y locations could vary due to different monitor types, resolutions, DPI etc.

One way is to create a mapping system which has a table of different monitors resolution and controls positions.

So using C# you read the monitor resolution and then based on the mapping move the mouse to the right position.
Avatar of romiebehunin
romiebehunin

ASKER

Yep that was actually a part of the initial solution. I did this by creating a table that would contain the names of each control and predetermined x,y coordinates for various resolutions. So we would have something like this:
A_Name, X,Y
B_Name, X,Y
C_Name, X,Y

Where A, B and C were specific resolution identifiers like 1024x768 etc etc

This has worked in the past without any trouble. At this point though I've run into a situation where there are so many different monitor sizes in use that my predetermined coordinates for a resolution (such as 1024x768, 96 DPI) were just slightly off causing the mouse click to just miss. I've even standardized the DPI, font, layout etc across these systems and while that helped on a few machines others still experienced problems (field not getting clicked and subsequently receiving focus).

I've also tried the setfocus api and passed it the windows handle of the control I was targeting but that (for whatever reason) does not work .

So that has me wondering if perhaps I can acquire those x,y locations at run time.
ASKER CERTIFIED SOLUTION
Avatar of romiebehunin
romiebehunin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Made it work!