vbalistviewpositionuserform

VBA UserForm Listview control - mouse click coordinates and positioning


VBA userforms, and listviews in particular, are tricky when it comes to spatial distances and coordinates. The question I am trying to solve is: the mousedown event gives the coordinates in pixles - how do I transform that into the units required for repositioning another user control and also incorporate the width property of user controls.

To give the very specific problem: I have a listview with multiple columns and a horizontal scroll bar. I want to get the selected row and column of the mouse click and then reposition a frame to the point at which the mouse was clicked.

Googling only came up with partial answers - nothing solving the full problem.


Solution

  • There are three different units of measurement. Pixels, twips and imperial points.

    Once you have gotten your functions/subs down to convert between pixels, twips and imperial points, you can then use the correct coordinate units for each different task: