Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-12-06
4
Medium Priority
?
562 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

715 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