dcsimg
Results 1 to 4 of 4

Thread: Units of width and height in VB6/VS6?

  1. #1

    Thread Starter
    Lively Member kutlesh's Avatar
    Join Date
    Jun 2018
    Location
    Skopje, Macedonia
    Posts
    124

    Units of width and height in VB6/VS6?

    I have never worked serious projects in VB6 so I cannot brag about it. One thing that baffles me is the number that is placed in the property sheet of the current VB6 form I work on.
    Width has value of 9724 and height is 6448 which doesn't seem to be pixels since the form is like 800 by 600 screen pixels.

    What is the name of the display units in VB6 and how can I translate those values to number of pixels on screen?

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,451

    Re: Units of width and height in VB6/VS6?

    Most objects that are containers (forms, pictureboxes, usercontrols) have a scalemode property: pixels, twips, inches, centimeters, etc. While in design (or @ runtime), changing the scalemode property changes values based on the scalemode.

    Controls placed in the container reflect their positions/dimensions in the container's scalemode. Their events X,Y parameters are in that scalemode. If the container has no scalemode property, twips is the default. OCXs may be different.

    So 9724 is likely 648 pixels if scalemode is twips & form is being designed at normal 96 DPI.
    VB6 has two functions for converting values between scalemodes: ScaleX & ScaleY. These are methods available from forms, pictureboxes, usercontrols.
    Code:
    Debug.Print ScaleX(9724, vbTwips, vbPixels)
    This should get you started.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    Hyperactive Member
    Join Date
    Aug 2017
    Posts
    268

    Re: Units of width and height in VB6/VS6?

    Quote Originally Posted by kutlesh View Post
    Width has value of 9724 and height is 6448 which doesn't seem to be pixels since the form is like 800 by 600 screen pixels.
    According to Height, Width Properties:

    Quote Originally Posted by MSDN
    For Form, Printer, and Screen objects, these properties are always measured in twips.
    Quote Originally Posted by kutlesh View Post
    What is the name of the display units in VB6 ...
    It's called Twip.

    Quote Originally Posted by kutlesh View Post
    ... and how can I translate those values to number of pixels on screen?
    You could also use the Screen object's TwipsPerPixelX & TwipsPerPixelY properties.

    Code:
    Private Sub Form_Load()
        MsgBox (Width / Screen.TwipsPerPixelX) & " x " & (Height / Screen.TwipsPerPixelY), vbInformation
    End Sub

  4. #4
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,508

    Re: Units of width and height in VB6/VS6?

    Originally Visual Basic was a merger of Microsoft's BASIC language with a Windows Form generation tool written by another party. As the standard for print measurement was based on Points, i.e. 72 points per inch of paper, the original developer wanted a scale that mapped directly to points, but with finer resolution than points, so chose to divide the point into TWenty parts, so called it twips meaing a TWentieth Interval of Point (or something to that effect).

    So, if you draw out a line on paper, you should have 20x72 or 1440 twips per inch of paper. Given that printers of the day were usually 300 dpi to 600 dip, with some maybe 1200 dpi, the 1440 dpi was considered more than precise enough for laying out accurate forms for printing. Also, back in the day, monitors were generally mapped to a couple of common resolutions, i.e. 96 dpi and 120 dpi, so the TwipsPerPixel values were correspondingly 15 (15 * 96 = 1440) or 12 (12 * 120 = 1440). Those were the good old days, when DPI resolution were an easy thing to account for.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width