VB6 Problem with Height and Width

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • redan
    New Member
    • Aug 2007
    • 2

    VB6 Problem with Height and Width

    Hello,

    I have a code in which I set the size of the window before they are open, like that :

    Public Sub Form_Load()
    Me.width = 8160
    Me.Height = 5970
    Me.Show
    End Sub

    However, two days ago I bought a new computer with (new graphic card is matrox and old one was NVIDIA) and ever since I got this computer the size of the windows are totally different from what I set in "Form_Load" . $



    What can I do ?

    Thanks in advance!!
  • Robbie
    New Member
    • Mar 2007
    • 180

    #2
    This is because you will be running at a different resolution.
    What VB measures (Width and Height) and (Left and Top) in by default is called Twips. The ratio between a twip and a pixel differs depending on the display resolution of the computer which the program is run on.

    What you need to do is tell it the size in pixels.
    To do this, set the ScaleMode of the form to 3 - Pixel.
    The two properties ScaleWidth and ScaleHeight will now be showing the width and height of the form in pixels.
    But alas, you can't simply change ScaleWidth and ScaleHeight! VB Thinks you are changing the ratio between (Width and ScaleWidth) and (Height and ScaleHeight) if you try to do this.

    Use this code to do it:
    Code:
    Me.Width = WidthInPixels * (Width / ScaleWidth)
    Me.Height = HeightInPixels * (Height / ScaleHeight)
    ...where WidthInPixels and HeightInPixels are simply the width and height which you want the form to be. This way, the form will turn out to be the same width and height (in pixels) no matter what display resolution the program is run on.
    Last edited by Robbie; Aug 20 '07, 12:09 PM. Reason: Fixed major error in code (back to front!)

    Comment

    • redan
      New Member
      • Aug 2007
      • 2

      #3
      Hello Robbie,

      Thanks!

      So basically, If I want the size of the window to be 6000 by 8000 (height by width).

      I have to do this.

      Code:
      Me.ScaleMode = vbPixels
      Me.ScaleHeight = 6000
      Me.ScaleWidth = 8000
      Is it correct ?

      Comment

      • Robbie
        New Member
        • Mar 2007
        • 180

        #4
        Originally posted by redan
        Hello Robbie,

        Thanks!

        So basically, If I want the size of the window to be 6000 by 8000 (height by width).

        I have to do this.

        Code:
        Me.ScaleMode = vbPixels
        Me.ScaleHeight = 6000
        Me.ScaleWidth = 8000
        Is it correct ?
        No, unfortunately you can't do it by changing the ScaleWidth and ScaleHeight. -_-
        That won't change the size at all.
        Use the little code example I gave before, at the bottom of my post.
        You're going to need to work in pixels instead of twips though, and 6000 by 8000 pixels is unbelievably big. It's going to have to be nearer 600x800.
        Just replace in my code where I put WidthInPixels with 600 and HeightInPixels with 800.
        Code:
        Me.Width = 600 * (Width / ScaleWidth)
        Me.Height = 800 * (Height / ScaleHeight)
        Put that code there and you should see what I mean. Only change the 600 and 800 bit though, to what you want your form size to be, in pixels. Sorry that it seems we need to change from twips to pixels, but that's why I don't use twips, because the size they represent changes if your display resolution does, e.g. in 800x600, 1 twip is not the same size as it is in 1024x768
        Last edited by Robbie; Aug 20 '07, 02:05 PM. Reason: Gave an example

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          I think you'll find Screen.TwipsPer PixelX and Screen.TwipsPer PixelY are a valuable source of information in this regard.

          Comment

          • Robbie
            New Member
            • Mar 2007
            • 180

            #6
            Originally posted by Killer42
            I think you'll find Screen.TwipsPer PixelX and Screen.TwipsPer PixelY are a valuable source of information in this regard.
            Thanks Killer! That's really useful info.

            Now Redan, if you could put your old graphics card back in =/, so you could find what Screen.TwipsPer Pixel X/Y are with it, you could do this:

            OldGraphicsTPPX = What Screen.TwipsPer PixelX is on your old graphics card
            OldGraphicsTPPY = What Screen.TwipsPer PixelY is on your old graphics card

            Then this would work on your old graphics card, new one, and any other one:

            Me.Width = 8000 * (OldGraphicsTPP X / Screen.TwipsPer PixelX)
            Me.Height = 6000 * (OldGraphicsTPP Y / Screen.TwipsPer PixelY)

            ...unless Killer knows a better way which doesn't involve taking in and out graphics cards, hahaha... -_-;

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Well, I think all you need to know is what resolution was used before the switch. The actual card shouldn't matter.

              Comment

              • Robbie
                New Member
                • Mar 2007
                • 180

                #8
                Originally posted by Killer42
                Well, I think all you need to know is what resolution was used before the switch. The actual card shouldn't matter.
                Yes, unless the old one was at a resolution which the new one can't do, or he just doesn't know what resolution was used. =/

                Comment

                Working...