Page 3 of 6 FirstFirst 123456 LastLast
Results 31 to 45 of 78

MS Access - X Y Cordinates of Control Top

  1. #31
    ironfelix717 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    75
    Hi Isladogs. Thanks for your reply and sample.



    First, some comments and replies:

    I agree that the listbox item can be highlighted using mouse move (it was in my example as well)
    What I'm unsure about is how to select that item just using mouse move
    Is that covered in listboxselector? Otherwise if I've missed it and your code does that, please can you tell me where it is
    I guess i don't really understand the question. Select = Highlight. Highlighting and selecting are synonymous in terms of code:

    Code:
    listbox.selected(5) = True
    To be clear on my end, at any time where i've said "select" I am referring to the above code.
    From the start, you have seemed VERY reluctant to pass on full details of your intentions! It would be much more useful if you gave a clear statement of intent
    Recent searches in the Access app or recent browser searches? Or something else entirely?
    Either way, rather than me reinvent the wheel, it would indeed make sense for you to provide code you've already done
    It is true I am discrete and with good reason. I know Access pretty well in terms of what controls can and cannot do and what tricks you can do to make them cool, it appears you do as well.
    If i thought there was another solution, I would've asked specifically for that in my OP. Again, I don't see how the content of the listbox is contributing to the problem, but i'll pass an SQL string to the procedure from a query of recent searches. I.e. User searches for "UID103983" consistently - that gets populated in the listbox to save the user time. Standard concept today. The only alternative I can ponder is using a combo-box, which defeats this entire post. But I don't believe I can permanently hide the dropdown arrow. When a control gets focus, it comes to the front. So its frustrating, but frustration is a result of my stubbornness and strict requirements, I suppose. All the code is in the latest sample I provided. Oh and i do apologize for accidentally including junk code. I forgot to remove when I exported...


    In regards to the Twips to Px conversion, it is rounded, but hardly. Lets assume the dropdown listbox will never exceed 5 inches (quite a generous assumption) - Over 5 inches, my error results in:
    True conversion at 5 inches = 96 * 5 = 480 pixels
    My conversion at 5 inches = (1440 * 96) * 0.0666667 = 480.00024

    ... I am losing 2.4 ten-thousandths of a pixel in error. Enough to never be a concern. Of course, when the code is ironed out, I will use the proper conversion to eliminate any doubt.

    But you are indeed correct that my code does not account for display change scale, because I simply don't understand all the variables that go into determining the XY pixel location even minutely as well as you do.



    So I looked at the new sample you provided. You should know there are some errors that just stemmed from confusion passing database back and fourth.

    In every instance where the form was referenced, the old form was referenced. So I would re-verify that you are actually getting the correct results. Every label in the code is under the old form because they were not changed and this will obviously show false results.
    Forms("Main_Form") should be Forms("Main Form_1"). I would just delete the "Main Form".
    If these are correct, and the labels are aligning to one another, the listboxselector should work and highlight lbTest as the mouse moves over it.


    Honestly, If I can understand every single entire variable that goes into determine the XY position of a control, I can easily write some code to check for each condition (is the ribbon hidden? Is the window maximized? Is there a record selector?)...

    See attached. I've developed a cleaner form for you and I to examine these counterparts. I welcome you to use it and see if you can develop something that is consistent if you hide/show ribbon, remove header, change header, etc.

    To give some more info...
    1.) Floating forms (pop-up) would be nice to have this feature but if we can only make it work within the app window, I am OK with that.
    2.) If the app window is minimized or resized, I will probably just disable this feature - but if its a simple matter of using a resize event or something then might as well include it.
    3.) I only need Y Axis cords, but X-Axis would be valuable for the sake of the community.



    Regards
    Attached Files Attached Files
    Last edited by ironfelix717; 02-10-2019 at 11:48 AM.

  2. #32
    isladogs's Avatar
    isladogs is offline Voodoo Is Practised
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    3,009
    I'd written most of the response below before you edited your last reply and attached a file

    Quote Originally Posted by ironfelix717 View Post
    I guess i don't really understand the question. Select = Highlight. Highlighting and selecting are synonymous in terms of code: listbox.selected(5) = True
    When you move over an object, it is NOT selected unless you click on the object using mouse or keyboard
    That's a standard Windows feature - for example in Explorer - not just in Access
    So whilst the listbox item is highlighted (if you hold the mouse down), it is very easy to prove that nothing has been selected unless you let go over the mouse again.

    If you do a web search there are a number of articles with various suggested approaches to overcoming this issue.
    I tried several of the approaches I found but none worked for me
    Here are two I didn't try: https://forums.hexus.net/software/17...a-listbox.html, https://bytes.com/topic/access/answe...over-event-vba

    I was wondering whether there was some 'magic' in the 'listboxselector' code to somehow select the code because moved over.
    It seems there isn't ...unless I'm missing something of course.

    It is true I am discrete and with good reason....
    If i thought there was another solution, I would've asked specifically for that in my OP. .....
    The only alternative I can ponder is using a combo-box, which defeats this entire post. But I don't believe I can permanently hide the dropdown arrow. When a control gets focus, it comes to the front. So its frustrating, but frustration is a result of my stubbornness and strict requirements, I suppose.
    It may have been obvious to you that the purpose was generic but I'm not a mind reader. It wasn't clear to me before
    I'm not quite sure why you are so opposed to combo boxes but lets not dwell on that
    Perhaps there are other simple solutions...!
    ActiveX listboxes (and combos) exist. I never use them but perhaps worth exploring?

    Also, the form below has a continuous subform and a listbox. Can you tell for certain which is which?
    Click image for larger version. 

Name:	Listbox&ContForm.PNG 
Views:	34 
Size:	7.8 KB 
ID:	37384
    It would be MUCH easier to select a record in the continuous subform than in the listbox!

    All the code is in the latest sample I provided. Oh and i do apologize for accidentally including junk code. I forgot to remove when I exported...
    Forms("Main_Form") should be Forms("Main Form_1"). I would just delete the "Main Form".
    If these are correct, and the labels are aligning to one another, the listboxselector should work and highlight lbTest as the mouse moves over it.
    I had realised, deleted the old form, renamed as Main Form and rechecked!
    It didn't actually matter as you made no use of the 'listboxselector' code in the form I was looking at
    I tried adding it but couldn't see anything useful by doing so .. perhaps I'm being very dense.

    Anyway, after all that preamble, I have got somewhere!
    My solution is a kludge & I need to do some more testing before I'm prepared to upload it
    I wanted to attach a video clip inline but can't see how to do so on this site. What format did you use to do so last time?

    Here is a screenshot ...

    Click image for larger version. 

Name:	MouseMoveListBox.PNG 
Views:	34 
Size:	18.8 KB 
ID:	37382

    The listbox has 2 columns and as you move over it (with or without holding the mouse down), the first column is shown in RED and the second column in a textbox
    So you can tell its being done live, I've re-used that somewhat irritating feature to move the red number down as the cursor is moved
    BTW I originally included that as I thought that was part of your wishlist!

    The attached zip file includes both MP4 & WMV formats in case you can't open one of them

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

  3. #33
    isladogs's Avatar
    isladogs is offline Voodoo Is Practised
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    3,009
    Last post for today on this subject.

    I've now applied the same idea on a listbox of images:
    Click image for larger version. 

Name:	ListBoxImagesMouseMove.PNG 
Views:	34 
Size:	30.0 KB 
ID:	37386

    The attached zip file includes a short video clip of it in use in both MP4 & WMV formats.

    Tomorrow will be the real test - I'll try it on another PC with different screen size & resolution
    Attached Files Attached Files
    Last edited by isladogs; 02-10-2019 at 03:28 PM. Reason: Extra comment
    Colin (Mendip Data Systems), previously known as ridders52 : Website, email
    If this has helped, please click the star button and leave a comment

  4. #34
    ironfelix717 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    75

    Post

    Isladogs,

    Thanks for replying. Yeah sorry about the edits. I was adding stuff as it came to me.


    When you move over an object, it is NOT selected unless you click on the object using mouse or keyboard
    That's a standard Windows feature - for example in Explorer - not just in Access
    So whilst the listbox item is highlighted (if you hold the mouse down), it is very easy to prove that nothing has been selected unless you let go over the mouse
    There should be no mention of a mouse-down event. We are not using the mouse-down event at this point. We are "hovering" above the listbox and using the mouse XY location to artificially select the values in the listbox as the mouse moves (HIGHLIGHT). I assume you know, a listbox does nothing until you code it to do so. I can mouse-down on a listbox, double click, mouse-up, you name it... nothing will happen except the item will be highlighted. It is a visual tool, has nothing to do with actually executing code from it---------- until you code it to do so. With a click_event or mouse_down event.

    You can easily grab the item of a listbox selected (highlighted) item as pictured in below animation where i doubleclick and store the value in the textbox. Alternatively, I can do this with a single click event.... This is 100% what happens in a web browser search bar.... If you are unsure on how to code this, I can post a basic sample.

    See below animation. (p.s. - download https://www.screentogif.com/ - Export as .GIF and insert as image.

    Click image for larger version. 

Name:	animate2.gif 
Views:	36 
Size:	40.9 KB 
ID:	37387


    OK so personally I think we should take a step back here and re-examine the root problem. There are multiple topics inter-twined making both your time and my time unproductive.

    In simple words, i will break down the goals and caveats.
    • Goal is to create a dropdown on any textbox. Thats the easy part.
    • The difficult part is that the dropdown list must highlight each item as the mouse moves over it.
    • A combobox natively does this mouse-over event, but i prefer to not have the arrow - sure its a minute detail, but is important to me
    • The best control to do this with is a listbox
    • Problem with listboxes are they don't highlight each item (i.e. select) on mouse-over natively.
    • We do that with Mouse_Move API and code.
    • I need the XY cords of a control on a form to make this work.
    • If this can't be done, then I need to use a combobox and try to eliminate the arrow.
    • Or i need to consider a new control - like another form or something
    • Regardless of the control type / method - I require a solution which is used easily (avoiding 10 different events and procedures) and can ideally be called from 2 or so functions / procedure
    • The listbox method is the cleanest control to do this with - but until XY cords can be obtained consistently, this will not meet requirements.


    I think with the work you've done on attempting to calculate the XY of a given control is a ground-breaking thing. Surely, i think it will be difficult to consider all the properties of a form (header, footer, scrollbars, etc). But nonetheless i do believe it is possible. Perhaps though, this is not worth the time and I must yeild to the combo-box

    Im going to play with a combobox now and see if I can get the arrow to hide. Will report back,

    Thanks for your help with this.

    Regards

  5. #35
    isladogs's Avatar
    isladogs is offline Voodoo Is Practised
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    3,009
    Hi
    Its late here and I'm logging off shortly

    Thanks for the screentogif link - I'll try it tomorrow
    My screen recording software can also produces animated gifs but the site converted them to static jpgs! Hence use of MP4/WMV.
    For my future info could you view both of them?

    There should be no mention of a mouse-down event. We are not using the mouse-down event at this point. We are "hovering" above the listbox and using the mouse XY location to artificially select the values in the listbox as the mouse moves (HIGHLIGHT). I assume you know, a listbox does nothing until you code it to do so. I can mouse-down on a listbox, double click, mouse-up, you name it... nothing will happen except the item will be highlighted. It is a visual tool, has nothing to do with actually executing code from it---------- until you code it to do so. With a click_event or mouse_down event.
    Yes - that was precisely the point I made in my last post!

    You can easily grab the item of a listbox selected (highlighted) item as pictured in below animation where i doubleclick and store the value in the textbox. Alternatively, I can do this with a single click event.... This is 100% what happens in a web browser search bar.... If you are unsure on how to code this, I can post a basic sample.
    [/QUOTE]

    I am well aware how to select a listbox item by clicking it. In fact I did that the file I uploaded in post #24.
    I've been exploring how to 'artificially select' items by moving the mouse over them whether or not the mouse button is held down
    The screenshot in my last post shows that I have succeeded in doing that.
    I've deliberately not YET applied the code to highlight the listbox when moving the mouse over it (though I will do later)
    I wanted to show that I could select the items whether or not it was highlighted

    In fact further testing has shown that it still works perfectly with:
    a) nav pane maximised/minimised or hidden
    b) ribbon maximised/minimised or hidden
    c) application window maximised or just covering part of the screen

    Changing the border style has made some slight discrepancies but these should be easy to fix

    I also need to do some adjustments to cope if the screen display is enlarged
    I should be able to adapt your 'listboxselector' code for that purpose.

    Still to do:
    I need to check the results if I change the font name or point size
    Similarly I've not yet tested on other computers
    Finally I want to apply form resizing code which I often use

    I've carried on with this because I found it an interesting challenge.
    When I'm happy with its reliability, I'll upload it for others to try including yourself

    Hopefully what I've done will help you achieve your aims.
    By design, I don't believe you can cover the arrow on a combo ...when it has focus ... I tried!
    I think you should look at a continuous form as well - much easier than a listbox and very similar in lots of ways

    The listbox method is the cleanest control to do this with - but until XY cords can be obtained consistently, this will not meet requirements.
    .... Surely, i think it will be difficult to consider all the properties of a form (header, footer, scrollbars, etc). But nonetheless i do believe it is possible.
    As stated above, I believe I've already cracked that or at least I'm 95% of the way ...

    @Orange
    Sorry I keep forgetting to thank you for your post.
    I already use my form resizing code and had considered using it ... but it looks like I've solved it anyway.
    Even so, I will have a look at the video in the next day or two
    Last edited by isladogs; 02-11-2019 at 08:19 AM.
    Colin (Mendip Data Systems), previously known as ridders52 : Website, email
    If this has helped, please click the star button and leave a comment

  6. #36
    ironfelix717 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    75
    Isladogs,

    It sounds like you're on to something. Though im not sure how you are doing that without trying the methods we've done already. Unless you are using them. Be curious to hear how you make out.

  7. #37
    isladogs's Avatar
    isladogs is offline Voodoo Is Practised
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    3,009
    I hope so.
    Not had time to do much more today and likely to be a couple of days till I do so.

    What I showed you yesterday made no use of your code.
    Currently trying to incorporate your mouse move listbox highlighting code but having having major problems with it
    Trying to keep that aligned with the cursor position is proving tricky.
    May end up having to retry other approaches.
    Colin (Mendip Data Systems), previously known as ridders52 : Website, email
    If this has helped, please click the star button and leave a comment

  8. #38
    ironfelix717 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    75
    Isladogs,

    I will await your reply in a few days. If you would be willing, I could play with your code and see if I can get the mouse to work. I'll continue to try and get the x-y cords of an object in the meantime

    Best regards

  9. #39
    isladogs's Avatar
    isladogs is offline Voodoo Is Practised
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    3,009
    Hooray. Its working!
    I spent ages trying to work with your listbox selector code but couldn't get it to work reliably.
    In the end I didn't use it at all.
    There is a MUCH easier method based on the listbox row height which I'll explain tomorrow when I'll hopefully upload the file

    Two video clips attached. Couldn't get them to work inline. These show:
    a) mouse move over a listbox to select various image files. It works with/without column headers; when form moved on screen; when font size increased/reduced and/or font name changed
    b) mouse move over listbox ( or click on it ) to open popup form to same record under the cursor. Optionally the popup form can move up /down the screen as the cursor moves
    Attached Files Attached Files
    Colin (Mendip Data Systems), previously known as ridders52 : Website, email
    If this has helped, please click the star button and leave a comment

  10. #40
    isladogs's Avatar
    isladogs is offline Voodoo Is Practised
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    3,009
    Hi again - following on from the two videos I posted yesterday, I've attached the working example app
    Its not a finished product and the screen flicker on mouse move can at times be very distracting
    This is a common issue with any mouse move code

    As you will see I didn't use your code in the end as it caused me lots of issues
    Instead I used code to calculate the height of each row in a listbox partly based on a demo by Stephen Lebans back in 1999
    The row height depends on a number of things and to complicate matters, the first row is 45 twips (3 pixels) taller than all following rows!
    As always, I am amazed by Stephen's ability to do things that us mere mortals would never achieve alone

    The info below is in a ReadMe.docx file that is included as part of the zip attachment

    ==========================================
    The attached example application includes an Images folder
    For the purposes of this example, this needs to be a subfolder of the Access example app

    The size of the navigation pane, ribbon and application window can be controlled from the startup form.

    There are 6 test forms available in this example:

    Forms 1 - 3 (Single/Continuous/Continuous Subform)
    Each of these is designed show how a zoom box can be used to view the entire contents of a standard textbox when it is too large to fit in the available space.
    Each form has 2 textboxes. Double click either textbox. The zoom box is opened / moved directly below the textbox.
    It should align whether or not record selectors / navigation buttons are used.
    Similarly, the border style should have no effect on the alignment.

    Form 4 & 5 - Listboxes
    The listbox selection opens / moves another popup form or displays an image for the selected/highlighted record
    The actions can be controlled using mouse move or a mouse click

    Records are NOT selected when moving the mouse over the listbox
    Code is used to determine the listbox position based on the calculated listbox row height and mouse cursor position.
    That information is used to highlight the record under the cursor so the data in the listbox record can be ‘read’ just as if it had been selected by clicking

    Options – mouse move code can be enabled / disabled
    Listbox options – column headers on/off ; change font and font size

    NOTE: Screen flickering can be an issue when using any mouse move code as in this example

    Form 6 - coordinate display
    This shows how coordinates can be updated as a control is moved on a form (using ‘nudge’ buttons) or as the form is moved around the screen


    NOTE:
    It is not possible to hide the application window for this example.
    Doing so would require the use of popup windows which isn’t possible due to the use of 2 forms simultaneously with forms 1-4

    ================================================== ===============

    I hope this helps you complete your ultimate aim & would be interested to see the final results when you have done so.

    I've got a couple of ideas for using the listbox mouse move highlight & 'select' cde in a real world app of my own.
    However I want to try & improve screen flicker first
    Attached Files Attached Files
    Last edited by orange; 02-15-2019 at 02:35 PM. Reason: edited by request--orange
    Colin (Mendip Data Systems), previously known as ridders52 : Website, email
    If this has helped, please click the star button and leave a comment

  11. #41
    isladogs's Avatar
    isladogs is offline Voodoo Is Practised
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    3,009
    Apologies - my previous post somehow got duplicated in the same post. Unfortunately I'm no longer able to edit it.
    Hope you found the example application useful
    Colin (Mendip Data Systems), previously known as ridders52 : Website, email
    If this has helped, please click the star button and leave a comment

  12. #42
    Ajax is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    6,600
    However I want to try & improve screen flicker first
    Colin, I've adapted my code for a form for your form4 mousemove to prevent screen flicker

    Code:
    Private Sub lstContacts_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        'if checkbox ticked, move the popup form on the right
       
        Dim LC As Integer
        Dim lstPos As Integer
        Dim intContactID As Integer
        Static oldLstPos
        
        
       
        Screen.MousePointer = 1
         If LBRH <> 0 And Me.chkMouseMove Then
               intLeft = Me.WindowLeft + Me.WindowWidth
               intTop = converttoTwipsY(GetYCursorPos) - intFormHeaderHeight
                      
               'LBRH =listbox row height - calculated in GetListboxRowHeight procedure
                 
                lstPos = -Me.lstContacts.ColumnHeads + (Y - 45) \ LBRH
                
                If lstPos <> oldLstPos Then
                    
                    LC = Me.lstContacts.ListCount + Me.lstContacts.ColumnHeads  '-1 to allow for header
                    Me.lstContacts.Selected(lstPos - 1 + Me.lstContacts.ColumnHeads) = True
                
                
                
                    'Debug.Print lstPos
                    'open / move the form
                    If lstPos > 0 And lstPos <= LC Then
                        DoCmd.OpenForm "frmContacts", , , "RecNum=" & lstPos
                        If Me.chkFormMove = True Then
                            'align contacts form with highlighted record in listbox
                             Forms!frmContacts.Move intLeft, intTop
                        Else
                            'align contacts form with top of listbox (approx)
                            Forms!frmContacts.Move intLeft, LBT
                        End If
                    End If
                    oldLstPos = lstPos
                End If
        End If
        
        Screen.MousePointer = 0
        
    End Sub

  13. #43
    ironfelix717 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    75
    Collin,

    I cannot test your file. Due to typemismatch on convert twips function:

    Code:
    Public Function converttoTwipsY(ByVal PixelY As Long) As LongDim lngDC As Long, intPerPixelY As Integer
    lngDC = GetDC(HWND_DESKTOP)
    Can you re-compile and fix errors?

    Note: I am on test system - 64bit win 10, 64 bit MS Access
    Thanks

  14. #44
    isladogs's Avatar
    isladogs is offline Voodoo Is Practised
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    3,009
    @Ajax
    Many thanks for that suggestion.
    I had to do a bit more tweaking but it has improved screen flicker on form 4 - though not eliminated it from the popup form
    However I've now applied the same idea to form 5 and that's now just about flicker free, Certainly good enough

    Ironfelix
    You posted just in time - was about to upload the new version
    The declarations are definitely correct for both 32-bit & 64-bit but I'll recheck the app on a 64-bit laptop.
    Just going out for a while but will hopefully upload v7 in a couple of hours time
    Colin (Mendip Data Systems), previously known as ridders52 : Website, email
    If this has helped, please click the star button and leave a comment

  15. #45
    Ajax is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    6,600
    though not eliminated it from the popup form
    I'm not experiencing any flicker on the popup form (perhaps a factor of processor power?) but suggest it is to do with constantly opening it. Suggest modify code to check if open and if not, open it. then your code here

    Code:
    ….
    ….
    If lstPos > 0 And lstPos <= LC Then
                        DoCmd.OpenForm "frmContacts", , , "RecNum=" & lstPos
    ….
    ….
    becomes

    Code:
    ….
    ….
    If lstPos > 0 And lstPos <= LC Then
                       forms("frmContacts").filter="RecNum=" & lstPos
                       forms("frmContacts").filteron=true
    ….
    ….
    air code, so may have to adjust for quotes in filter

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

Similar Threads

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

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