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.
.NET ProgrammingVisual Basic.NETProgramming

Avatar of undefined
Last Comment
romiebehunin

8/22/2022 - Mon
unknown_routine

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.
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
romiebehunin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
romiebehunin

ASKER
Made it work!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy