Page 1 of 6 123456 LastLast
Results 1 to 15 of 79

MS Access - X Y Cordinates of Control Top

  1. #1
    ironfelix717 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    128

    MS Access - X Y Cordinates of Control Top

    Hi,



    Have a bit of a challenge here...

    I am trying to get the X-Y coordinates of a controls location (textbox, listbox, or combobox) . Specifically, the bottom or top corner of that control. However, this needs to be obtained from code. The end result I desire is to slap a control anywhere on the form and run the code and retrieve the X,Y. Regardless of the form size.

    I have managed to obtain cursor X-Y cordinates using the GetCursorPos() API but that does not help me with dynamically getting a controls X-Y cordinates.

    Therese a good thread here but it never resulted in deriving the X-Y from a control...

    https://www.accessforums.net/showthread.php?t=57244

    P.S. I do in fact need the X-Y of the control and no other solution exists to solve my problem.



    Hoping to get some feedback. Thanks for your help!

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    6,289
    P.S. I do in fact need the X-Y of the control and no other solution exists to solve my problem.
    Then I must be misunderstanding when I propose it's the top property and the left property that you want, as in forms!form1.command10.left
    It's relative to the section that contains the control. Not sure of the implications if the control is on a subform/subreport as I've never needed to get these properties. Set them, yes. Get them, no. The form has to be open, either in design or form view.
    - "doesn't work" is no help. Post err msgs and where.
    - Use code tags for code/sql. Implement changes in copies of your database.

  3. #3
    ironfelix717 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    128
    Hi micron,

    The .top and .left properties are useless in my context unless I can convert them to a x-y cordinate.

  4. #4
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    3,737
    Have a look at this example where I place a second form directly below a selected control in the first form
    Although the purpose is different and indeed more complex, the code to do what you need should be in the example app

    Hope that helps
    Attached Files Attached Files
    Colin (Mendip Data Systems) : Website, email
    If this has helped, please click the star button and leave a comment

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    14,290
    I'm not sure if this is relevant to your post, but here is a link to an article regarding control coordinates by a former colleague (AD Tejpal) from a different forum . It may offer some ideas.
    He wrote several articles (technical/concepts/instructional) which may still be located at RogersAccessLibrary.

  6. #6
    ironfelix717 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    128
    Isladogs,

    Thanks for contributing to my problem... But as in my reply to Micron, I specifically need the X Y coordinates of the control. Making use of the .Top or .Left positional properties provides no solution to my problem (which has not been described). The only solution is unfortunately to retrieve the XY cordinates.

    orange,

    The post is interesting but I can't understand it and dissecting the code, he is not retrieving the XY cordinates of a arbitrary control. In fact, I have no idea what he is doing because I don't use built-in bound tools in Access to develop a database application.


    I may have to seek the MSDN forum... I realize this is a very difficult request, but if this request is satisfied, I believe I can develop something very cool (which I would share with the community, obviously).

    Thanks for you help!!


    Thank you also.

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    14,290
    Making use of the .Top or .Left positional properties provides no solution to my problem (which has not been described). The only solution is unfortunately to retrieve the XY cordinates
    .

    Perhaps you could describe your problem even if by analogy.

    I looked at Colin's database. Specifically the Text2 textbox. His dbl click event shows how he calculates the position for where to move the Orange box.

    I uncommented his Debug.print statement and attempted to print the coordinates ( Top left) x/y coords.
    I then move the text2 position and ran the dbl click again. The numbers in pixels seems reasonable and if I have misunderstood or misrepresented the proper coordinates, I think the info you need can be determined in a similar manner.

    Code:
    Private Sub Text2_DblClick(Cancel As Integer)
    
        strText = Me.Text2
        
        intLeft = Me.WindowLeft + Me.Text2.Left
        intBase = intFormHeaderHeight + intRecSelHeight + Me.WindowTop + Me.Text2.Top + Me.Text2.Height
        
        Debug.Print "Re Text2 top/left x coord " & intLeft & "   y coord " & intBase
         'move the orange box
       Me.Box9.Left = Me.Text0.Left
       Me.Box9.Top = Me.Text0.Top + Me.Text0.Height
        
        'open/move the form
        DoCmd.OpenForm "frmZoom"
        Forms!frmZoom.Move intLeft, intBase
       
    
    End Sub
    Results of the 2 tests
    Re Text2 top/left x coord 5889 y coord 6018
    Re Text2 top/left x coord 5253 y coord 6069


    Can you also be specific as to what/how Isladogs(Colin) approach misses the mark?

  8. #8
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    3,737
    I'm also unclear what issue the OP has with the approach in my example app
    The coordinates supplied in the debug line take into account the position of the form on the screen as well as the position of the control on the form
    Double clicking moves the popup form to just below the control that was double clicked because that was what I wanted for that particular app
    If you move the form on the screen, the code still ensures the popup moves to the correct place

    Code:
    intLeft = Me.WindowLeft + Me.Text2.Left
     intBase = intFormHeaderHeight + intRecSelHeight + Me.WindowTop + Me.Text2.Top + Me.Text2.Height
    It should hopefully be obvious what you need to change to get the top position of the control rather than its base as I have done

    no solution to my problem (which has not been described).
    If you ask for our help, its reasonable to give us some idea what the purpose is
    Colin (Mendip Data Systems) : Website, email
    If this has helped, please click the star button and leave a comment

  9. #9
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    6,289
    Isladogs, I didn't download your file, so sorry for what might be a pointless post, but if it relates to the x y coordinates of the screen (or perhaps application window) then I would think it should fit the bill. Unfortunately what's needed might not have been expressed as clearly as it could have been. I suspect that's what is wanted, not the position of the control relative to the section containing it as I first thought.

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    14,290
    Micron,

    I believe that's what Colin's post shows. The x,y coordinates given account for the window position, the form section/position and the control position.
    That is why I'm confused with the OP's requirement.

  11. #11
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    3,737
    Just to make the point clearer, here is a new example.

    The co-ordinates of each textbox within the application window are calculated when the form is opened.
    If the form is dragged to a new position on the screen, the coordinates are updated

    The values are the sums of the horizontal and vertical arrow components so take into account:
    a) form position within the application window
    b) height of title bar & form header
    c) control position on the form

    Click image for larger version. 

Name:	CoordTest.PNG 
Views:	56 
Size:	76.2 KB 
ID:	37343

    As this is only intended for clarification, I should stress what its not doing in this version
    d) allowing for record selector width (though I've done that in another example)
    e) position of Access application window with reference to the overall screen
    It will also not be updated if the navigation pane width is changed or the ribbon is minimised/maximised

    All of those are possible with additional code
    However as we've no idea what the OP wants there's little point doing any more at this time
    Attached Files Attached Files
    Colin (Mendip Data Systems) : Website, email
    If this has helped, please click the star button and leave a comment

  12. #12
    Ajax is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    7,553
    the x:y coodinates of a control, or a window within the access window are measured in twips. the x:y coordinates of the access window on the monitor are measured in pixels.

    So the x:y coordinates of a control within a form and the x:y coordinates of the form within the access window (assuming the form is not a popup) needs to be converted to pixels and then added to the access window pixels . Can't remember whether the top parameter is relative to the section or the form, so may also need to include the height of the page header if used.

    If the OP is familiar with getCursorPos, he has the code to convert twips to pixels.

    The end result I desire is to slap a control anywhere on the form and run the code and retrieve the X,Y. Regardless of the form size.
    This I do not understand. The implication is the form is in design view to 'slap a control' onto it. But vba will not run until the form is in normal view - it may be possible to run vba from some other open form to look at a form in the allforms collection, but until the edited form is saved it won't be in that collection and I suspect if open in edit mode, will block other code trying to open it in edit mode.

    Without understanding the OP's reason for this requirement or, since the requirement does not make sense, a clearer explanation of what is actually required, I don't see why Colins suggestion does not meet the requirement since this is closest to (everyones?) understanding

  13. #13
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    3,737
    Also FWIW, I have code to convert pixels to twips and vice versa
    Colin (Mendip Data Systems) : Website, email
    If this has helped, please click the star button and leave a comment

  14. #14
    Ajax is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    7,553
    I think most serious developers do

  15. #15
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    3,737
    LOL
    The comment was intended for the OP in case it helped
    Colin (Mendip Data Systems) : Website, email
    If this has helped, please click the star button and leave a comment

Page 1 of 6 123456 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 9
    Last Post: 07-13-2018, 02:18 PM
  2. Replies: 3
    Last Post: 11-30-2016, 07:18 PM
  3. Replies: 4
    Last Post: 02-18-2016, 12:06 PM
  4. Replies: 8
    Last Post: 06-19-2015, 02:19 AM
  5. Tab Control in Access
    By Rosy6 in forum Forms
    Replies: 2
    Last Post: 04-25-2010, 12:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Tech Forums: Microsoft Office Forums