Solved Position Form to Mouse Pointer (1 Viewer)

Noson5434

New member
Local time
Today, 16:01
Joined
Jan 25, 2023
Messages
26
Hey I need help regarding form positioning

I have a continuous form with a button to view that records comments.
I want to open a form (frmComments) and position that form where the users mouse is (so technically by the button they clicked to view the comments).
How can I achieve this?

Thanks in advance.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:01
Joined
Oct 29, 2018
Messages
21,474
Hi. Welcome to AWF!

Looks like command buttons have mouse events. Maybe you can use it to determine the mouse location.
 

Noson5434

New member
Local time
Today, 16:01
Joined
Jan 25, 2023
Messages
26
Hi. Welcome to AWF!

Looks like command buttons have mouse events. Maybe you can use it to determine the mouse location.
Glad to be a member.

How would I open a form based on that?
Is SetWindowPos API a way to do so?
If so how would I implement that?

Thanks
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:01
Joined
May 21, 2018
Messages
8,529
@isladogs has the code to precisely position a form

There is a lot to dig through in that example. I took a snippet of that code and used it in the link below to position my popup that looks like a MVF.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 21:01
Joined
Feb 19, 2013
Messages
16,616
On my phone so can’t provide a link but in the form open event use the getcursorpis api and I think use something like

me.move left,top,width, height

edit - links just provided will be a good resource
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:01
Joined
May 21, 2018
Messages
8,529
If looking at my example code. You need the form dimension module and my code to position the popup just under the cmbobox is
Code:
  Dim fd As FormDimensions
   Me.Moveable = True
   fd = GetFormDimensions(Me.ParentForm)
   intleft = Me.ParentForm.WindowLeft + Me.AssociatedComboBox.Left + Me.AssociatedComboBox.Width + fd.intBorderWidth + fd.intRecSelWidth - m_ListWidth '+ intRecSelWidth
   intBase = Me.ParentForm.WindowTop + fd.intTitleBarHeight + Me.AssociatedComboBox.Top + Me.AssociatedComboBox.Height
In my example I am in the header. If you look at @isladogs example this will work (and is needed) for a continuous form.
 

Noson5434

New member
Local time
Today, 16:01
Joined
Jan 25, 2023
Messages
26
If looking at my example code. You need the form dimension module and my code to position the popup just under the cmbobox is
Code:
  Dim fd As FormDimensions
   Me.Moveable = True
   fd = GetFormDimensions(Me.ParentForm)
   intleft = Me.ParentForm.WindowLeft + Me.AssociatedComboBox.Left + Me.AssociatedComboBox.Width + fd.intBorderWidth + fd.intRecSelWidth - m_ListWidth '+ intRecSelWidth
   intBase = Me.ParentForm.WindowTop + fd.intTitleBarHeight + Me.AssociatedComboBox.Top + Me.AssociatedComboBox.Height
In my example I am in the header. If you look at @isladogs example this will work (and is needed) for a continuous form.
Thank you
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:01
Joined
May 7, 2009
Messages
19,245
there is code there Exact same request as you have with Code solution.

here is a demo from that site.
 

Attachments

  • demo.accdb
    604 KB · Views: 138
Last edited:

gontranharvey

New member
Local time
Today, 16:01
Joined
Oct 30, 2023
Messages
1
This solution is the best, I was using the @isladogs solution before, but it does't work if by exemple you have a continous form with 100 records and on the screen you are at the record 85, but in reality you are at the 10th record visible in the screen, so the popup goes so down outside the windows sceen. The @isladogs solutions multiply the height of the detail section by the current selected record (85).
@arnelgp thanks for sharing this solution.
 

Users who are viewing this thread

Top Bottom