By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,504 Members | 1,448 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,504 IT Pros & Developers. It's quick & easy.

Absolute Position of a Control

100+
P: 675
I want to know the absolute position (Left & Top) of a textbox control on a form. Form may be Continuous or Single, may or may not have a Header, may be FullScreen or not, etc.

I need this to overlay an automatic "Zoom Box" form on top of the textbox with focus when that textbox's ability to display the text being entered exceeds the size of the textbox. I want this form's textbox Left and Top to exactly match the textbox with focus, so it is not distracting to the user when it appears. Entry typing will not be interrupted. Obviously MoveSize method will be used.

OldBirdman
Dec 16 '08 #1
Share this Question
Share on Google+
9 Replies


FishVal
Expert 2.5K+
P: 2,653
Hello, OldBirdMan.

Look into Form.CurrentSectionTop and Form.CurrentSectionLeft properties.
This will help to obtain form coordinates of control regardless quantity and size of form sections as well as whether form is single or continuos view.

As for screen coordinates, it most likely you need to use some API like SetWndowPos() and GetWndowRect(). When I will get a time I will code some samples for you.

Regards,
Fish
Dec 17 '08 #2

FishVal
Expert 2.5K+
P: 2,653
Ok. Here is the sample.
Attached Files
File Type: zip ZoomTextBox.zip (38.1 KB, 721 views)
Dec 17 '08 #3

100+
P: 675
Thank you for the sample code. There is a couple of week's study here for my continuing education. I use a limited subset of Access. This is small enough for me to work with, therefore understand. It has features I didn't think of, and I will add some features I believe essential, like having the ESC key functional as CANCEL.

But it doesn't work in Access 2000:
With Me
.WindowLeft
Compile error: Method or data member not found

It does work in Access 2002, but that is the laptop, and I only use the laptop when travelling. It is not a nice keyboard to do much with.

On the laptop, if the form is maximized within the Access2002 window, the position is not correct. The Zoom window appears at the upper-left corner of a completely gray form, which is not maximized and seems to be in a random position. I guess I can't have everything. Thanks again.

OldBirdman
Dec 17 '08 #4

FishVal
Expert 2.5K+
P: 2,653
Ok.

I will look into it.
Dec 18 '08 #5

FishVal
Expert 2.5K+
P: 2,653
@OldBirdman
Ok. I've coded it with WinAPI. See attached example.

..
On the laptop, if the form is maximized within the Access2002 window, the position is not correct. The Zoom window appears at the upper-left corner of a completely gray form, which is not maximized and seems to be in a random position ...
Position is determined right it is really not random. But, unfortunately, when frmZoom is being opened it automatically goes into maximized state (gray area you see) and main form for some reason restore its size. The way around is not to use maximized forms but to set their size to application window. There are many examples all around the net how to do it, like this one .

Regards,
Fish
Attached Files
File Type: zip ZoomTextBox 2.zip (43.0 KB, 306 views)
Dec 18 '08 #6

FishVal
Expert 2.5K+
P: 2,653
Hello, OldBirdMan.

The last version of control coordinates determination - IMHO, a more robust one, and it works in all form views.

The logic is the following:
  • When Access opens a form it creates multiple windows. One window which is of particular interest is a window which is moved and resized to a control which gains focus.
  • WinAPI function GetFocus() (or more comprehensive GetGUIThreadInfo()) could be used to get handler to this window.
  • Screen coordinates of the window could be determined with GetWindowRect() function.
  • Thus obtained coordinates could be transformed to Access MDI window coordinate system with ScreenToClient() function.

Best regards,
Fish.
Attached Files
File Type: zip ZoomTextBox 3.zip (43.8 KB, 629 views)
Dec 24 '08 #7

100+
P: 675
Thank you for your continuing ideas on this subject.

It is taking awhile for me to work with this as there is much code that I do not understand. Trying to learn Access from Help alone creates a slow learning curve, but I haven't yet found any source that really addresses programming in Access.

I'm now trying to make this work, and also combine it with some of the logic I found in a small download "FormsInteractions.zip" from this site. Again, this presents new (to me) concepts and doesn't seem to work correctly when I try to expand and modify it for my needs. Probably my understanding of VBA.

OldBirdman
Dec 26 '08 #8

FishVal
Expert 2.5K+
P: 2,653
Hello, OldBirdMan.

If you've encountered difficulties while implementing concepts from examples attached to this thread and FormInteractions sample db or you want to get explanations on overall logic and/or particular parts of code, then please post you questions.
I will be happy to discuss it.

Regards,
Fish.
Dec 26 '08 #9

100+
P: 675
I work with a subset of Access, and a subset of VBA. Many of the non-experts asking questions on this site seem to be at a similar level, using controls from the Access Toolbox, and code with variables defined by "Dim" and altered with "[Let] varname = expression".

I'll add a field to a table, a workspace, so I don't have to create virtual tables, recordsets, or whatever. I add a lot of hidden controls on a form so I can reference data not shown. I posted a simple solution on the thread "creating a form that can select items and print them" started by "buddyr". This uses a field in the table to track the selections. To me, straightforward. This is the way I am using Access, and that is a sample of my coding.

New to me with these 2 small programs are Events and procedures other than Sub or Function, namely Property.

To ask questions about these here is way off-topic, and belong in new threads. So I will thank you for your time, and muddle onward using something new when I finally understand it.

From this thread I have decided that an automatic ZoomBox is fine, but to attempt to align it on any form, any position, is not going to work.

But maybe if I put enough time in it, I can understand Events, and then not have to have my forms opened Dialog, but can use Modal, which does not pause the code after the open statement. I've always tried to open these child forms as Dialog, and somehow pass the values thru OpenArgs or Global variables. Form_Load then initializes the controls on the form. Never thought of initializing from parent form.

I've been trying to open a child form with the same table as the parent, but cannot make it work. The answer to my problem may be in the short program "FormsInteractions", so I'm hopeful.

Any How-To questions I will ask in a new thread.
Dec 27 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.