VB6: How to switch to pixels instead of twips

vb6
19,095

Solution 1

I worked extensively with scalemode back in the day and all I can say is don't bother. It wasn't properly universally supported, which meant that you'll end up converting back to twips for some things anyway.

VB6 is twips based, like it or not, so if you try to do things pixel based, you'll be fighting the current the whole way.

Fortunately VB.net finally ended all that, and is completely pixel based, you can still alter you viewport scaling but .net seems to handle that much better than Vb6.

Solution 2

dim iInPixels as integer
dim iInTwips as integer

iInPixels = 200
iInTwips  = iInPixels * Screen.TwipsPerPixelX
iInPixels = iInTwips / Screen.TwipsPerPixelX

As @drventure said, you'll be rowing against the current the whole way, but it really isn't all that bad, as long as you can isolate the logic to a single spot.

Solution 3

Does the ScaleMode Property help?

Returns or sets a value indicating the unit of measurement for coordinates of an object when using graphics methods or when positioning controls.

Solution 4

Microsoft Knowledge Base article: How to Convert Twips to Pixels

The link above is for Access VBA but will work with VB6 as well. I'm not aware of native VB6 functionality to do what you need. From what I remember ScaleMode will not work for what you want to do (despite the fact that it seems to exist to solve your exact problem).

EDIT: As I'm thinking about it, ScaleMode did not solve my problem that I had at the time. Depending on what you are trying to do, it may solve your problem just fine. I'd certainly try that first since it will produce simpler, more maintainable code.

Solution 5

I did it this way. I got the Twips from Form1.Picture.Width and by dividing with pixelize you get pixels ANYWHERE in VB6 Script. In General Declarations
Const pixelize As Double = 26.45833333

Command3.Caption = "Pixels: " & Int(Form1.Picture.Width / pixelize) & "x" & Int(Form1.Picture.Height / pixelize)

Works for me, maybe you are helped.

Share:
19,095
ezpresso
Author by

ezpresso

Updated on June 07, 2022

Comments

  • ezpresso
    ezpresso almost 2 years

    I am refactoring a VB6 application. The measurements of any of the controls are in twips. Is it possible in VB6 to set a control to use pixels instead of twips? Thanks

  • CloudyMarble
    CloudyMarble almost 11 years
    Please add the actual answer