Absolute Position of a Control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • OldBirdman
    Contributor
    • Mar 2007
    • 675

    Absolute Position of a Control

    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
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Hello, OldBirdMan.

    Look into Form.CurrentSec tionTop and Form.CurrentSec tionLeft 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

    Comment

    • FishVal
      Recognized Expert Specialist
      • Jun 2007
      • 2656

      #3
      Ok. Here is the sample.
      Attached Files

      Comment

      • OldBirdman
        Contributor
        • Mar 2007
        • 675

        #4
        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

        Comment

        • FishVal
          Recognized Expert Specialist
          • Jun 2007
          • 2656

          #5
          Ok.

          I will look into it.

          Comment

          • FishVal
            Recognized Expert Specialist
            • Jun 2007
            • 2656

            #6
            Originally posted by OldBirdman
            ....
            But it doesn't work in Access 2000:
            With Me
            .WindowLeft
            Compile error: Method or data member not found
            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

            Comment

            • FishVal
              Recognized Expert Specialist
              • Jun 2007
              • 2656

              #7
              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 GetGUIThreadInf o()) 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

              Comment

              • OldBirdman
                Contributor
                • Mar 2007
                • 675

                #8
                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 "FormsInteracti ons.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

                Comment

                • FishVal
                  Recognized Expert Specialist
                  • Jun 2007
                  • 2656

                  #9
                  Hello, OldBirdMan.

                  If you've encountered difficulties while implementing concepts from examples attached to this thread and FormInteraction s 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.

                  Comment

                  • OldBirdman
                    Contributor
                    • Mar 2007
                    • 675

                    #10
                    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 "FormsInteracti ons", so I'm hopeful.

                    Any How-To questions I will ask in a new thread.

                    Comment

                    Working...