Solved

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

Posted on 2013-12-06
4
535 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 15

Expert Comment

by:unknown_routine
ID: 39701336
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
ID: 39701365
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
ID: 39730521
Solved this myself using UIAutomation
0
 

Author Closing Comment

by:romiebehunin
ID: 39737658
Made it work!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A short article about problems I had with the new location API and permissions in Marshmallow
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

738 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