Results 1 to 4 of 4
  1. #1
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post
    I have a custom button on an Excel toolbar that displays my Userform. In the Initialize event, I want to set the form's Left & Top property so that the form starts up close to the mouse pointer.

    Currently, I am using the GetCursorPos API, using the X & Y as Left & Top. This is OK when my application is in the upper-left corner of the screen, but as I move accross/down the screen, the GetCursorPos values that I am using for Left & Top are too big by about 30%.

    So, for now, I just subtract 30% & it is close, but I would like to know how to properly convert and why? Points, pixels, TIA --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts
    The API uses pixels, I think, so you'd need the Application.Pointstoscreenpixelsx and PointstoscreenpixelsY to convert them.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts
    IIRC the ratio from points to pixels is (usually) either 0.75 or 1/0.75
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  4. #4
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post
    [quote name='pieterse' post='786541' date='28-Jul-2009 10:42']IIRC the ratio from points to pixels is (usually) either 0.75 or 1/0.75[/quote]
    Thanks, Jan Karel! Since XL2K and earlier does not have PointsToScreenPixel..., (which was what I was looking for) .75 is the answer.
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •