Solved

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

Posted on 2013-12-06
4
503 Views
Last Modified: 2013-12-24
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.
0
Comment
Question by:romiebehunin
  • 3
4 Comments
 
LVL 15

Expert Comment

by:unknown_routine
Comment Utility
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.
0
 

Author Comment

by:romiebehunin
Comment Utility
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.
0
 

Accepted Solution

by:
romiebehunin earned 0 total points
Comment Utility
Solved this myself using UIAutomation
0
 

Author Closing Comment

by:romiebehunin
Comment Utility
Made it work!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

A short article about a problem I had getting the GPS LocationListener working.
A short article about problems I had with the new location API and permissions in Marshmallow
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now