Screen PerPixelX and PerPixelY For Metrics other than Twips

Intelligent Solutions Inc.

Version Compatibility:

More information:
Many Windows API functions require you to pass the width or height of a control in pixels (a device dependent metric). Normally, you do this by converting to pixels via the Screen.TwipsPerPixelX or Screen.TwipsPerPixelY properties. However, if the ScaleMode of your form is not vbTwips, this won't work

This .bas module provides the methods you need (e.g., InchesPerPixelX, InchesPerPixelY, PointsPerPixelX, etc.) to convert heights and widths from a non-twip based scale to pixels. It also includes ControlHeightInPixel and ControlWidthInPixel functions that provide a control's dimensions in pixels regardless of the form's scale mode.

Instructions: Click the link below to download the code. Select 'Save' from the IE popup dialog. Once downloaded, open the .zip file from your local drive using WinZip or a comparable program to view the contents.

Download perpixel.bas