Screen Pixels and Document Points Conversion

  • In trying to align commandbars etc (for which [code].Left [code]and [code].Width [code]returns pixels from left of screen) with document windows (for which [code].Left [code]and [code].Width [code]returns points from left of application window) I am having some difficulty.

    The conversion function
    gives results that are inconsistent.

    Anyone resolved this issue?

  • Re: Screen Pixels and Document Points Conversion

    Is it possible to include a post with what you have all ready. It seems that once long ago I had some success with placing forms ( not neccessarily tool bars ) exactly where I wanted them.

    But it's been awhile and I no longer have the app or code. So having yours might give me some place to start.

    Also more description on where you're trying to align the command bar up might have been useful.


  • Re: Screen Pixels and Document Points Conversion

    Just playing around here is a simple piece of code

    There are many issues. Like are the row headers visible or not. Are there toolbars docked top/bottom/left/right. You'll need to determine the height of the toolbars that are docked top and left. Also need to determine if the tool bars are docked in a stacked fashion or not.

    Simply put what I'd do is move ( via code ) undock all toolbars set the position of the toolbar in question. Then redock the toolbars and then increment the floating on to match.

    I'll test this idea.

  • Re: Screen Pixels and Document Points Conversion

    Check this out in your help

    "PointsToScreenPixelsX "

    Just found it myself


  • Re: Screen Pixels and Document Points Conversion

    WEll I'm baffled?


  • Re: Screen Pixels and Document Points Conversion

    OK, Thanks for the feedback All

    Thanks to xlite for” a location indicator, you can download FormPosition from CPearson:” I’ll look at it shortly.

    Sorry for the double post. My connection was up and down and in the process I must have inadvertently sent my initial cut of the message.

    I’ll have a go at attaching my rough userform workbook for exploring positioning.

    Seems to me that there are at least two sets of different sized pixels returned, one for UserForms and Applications,
    And one for Commandbars and Document Windows (once converted from points)-although these are not always equal to each other or in each direction.

    The workbook builds a commandbar (which is a distraction to this issue)
    The BLANK button on the right shows the modless userform, and passing the mouse over it updates the values.

    Change the windowstate of the application and the document window, and move them, the commandbar and the userform around to see the effect on the reported positions.
    Try lining up the edges to see the discrepancies.

  • Re: Screen Pixels and Document Points Conversion

    Oh dear, this is getting too complicated.

    I tweaked Chip Pearsons demonstration workbook to be modeless (to make it more interactive) and also to move the formatting toolbar to the same position as the userform, along the lines that Barry suggested.

    What more have I learnt? Or think I’ve learnt?
    1. The following all affect the conversion from pixels to points when using the builtin PointsToScreenPixelsX and PointsToScreenPixelsY methods.
    -number of toolbar rows in the docking area and
    -the zoom factor

    2. The datum for position properties returned as pixels is the top left of the screen.
    The datum for position properties returned as points, when converted to pixels, is the VIRTUAL top left corner of the document. (ie if you’re looking at cell IV65536 then the datum is several metres up and too the left) but when its initially returned in points it’s the top left of the application window.

    3. Chip’s workbook seems to work very well most but certainly not all of the time, and somehow he’s done it all without using the PointsToScreenPixels conversions. His method still gives the apparent result that pixels for commandbars and for userforms are different sizes. Ie Plot them at 0,0 and they both coincide at top left of screen (OK) Plot them near a cell midscreen and they do not conincide.

    4. Zoom factor affects the size of this discrepancy, both with Chip’s method, and using the PointsToScreenPixels methods. So, there is probably a simple scale factor that depends on the zoom factor.

    All I have been aiming for is to have a Commandbar or userform display near the top right hand side (probably just outside if there’s room) of the active document window, (and possibly both, to give the appearance that they are attached to each other) Chip’s approach comes close to this, and could be modified, but is still far too loose. (That doesn’t mean to say that I’m not very impressed with the effort he went to.)

    Unless anyone has some inspiration I’m going to abandon this as too time consuming.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!