PRB: Circle Aspect Ratio Unaffected by User-Defined ScaleMode

Last reviewed: October 30, 1995
Article ID: Q129893
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0
  • Standard and Professional Editions of Microsoft Visual Basic for Windows, version 3.0

SYMPTOMS

Lines (using the line method) drawn inside of a circle (using the Circle method) may have different aspect ratios. Therefore, lines that should have been an exact radius may be longer or shorter than the radius of the drawn circle.

CAUSE

The Circle method always draws a perfect circle. It measures the radius in the X direction. User-defined ScaleModes may have a defined unit in the X direction that is not equal to the defined unit in the Y direction. This causes the line lengths to be changed based on the User-defined Scalemode, but it does not affect the circle.

RESOLUTION

This is not a problem with Visual Basic. The circle always draws a perfect circle. It measures the radius in the X direction. The line method draws the segments the correct length in both directions. To fix this issue, you have to scale the Y coordinate or pick a better user-defined coordinate system where units in the X and Y directions are equivalent. The following shows the correct way to handle ScaleMode.

Replace the code shown in the "Steps to Reproduce Behavior" section of this article with this code:

   Sub Form_Click ()
      Dim X As Integer, Y As Integer, N As Integer
      N = 5
      X = 0
      Y = 0

      yscale = Form1.ScaleWidth / Form1.ScaleHeight  'added:

      Form1.ScaleMode = 0
      Form1.ScaleHeight = -3
      Form1.ScaleWidth = 3
      Form1.ScaleLeft = -1.5
      Form1.ScaleTop = 1.5

      Circle (x, y), 1, QBColor(n)
      Line (x, y)-(1, 0), QBColor(n)
      Line (x, y)-(0, 1 * yscale), QBColor(n)    'modified: added * yscale
      Line (x, y)-(-1, 0), QBColor(n)
      Line (x, y)-(0, -1 * yscale), QBColor(n)   'modified: added * yscale

   End Sub

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Add two Command buttons (Command1 and Command2) to Form1.

  3. Add the following code to the Click events for the command buttons:

       Sub Command1_Click ()
          Form1.ScaleMode = 5 'Inches
          Form1.ScaleLeft = 0
          Form1.ScaleTop = 0
    
          Dim N As Integer, X As Integer, Y As Integer
    
          N = 5
          X = 1
          Y = 1
    
          Circle (x, y), 1, QBColor(n)
          Line (x, y)-(2, 1), QBColor(n)
          Line (x, y)-(1, 2), QBColor(n)
          Line (x, y)-(-2, 1), QBColor(n)
          Line (x, y)-(1, -2), QBColor(n)
       End Sub
    
       Sub Command2_Click()
          '** Note: depending on what screen resolution you are running
          'the aspect ratio difference may differ. At 1024x768 resolution,
          'the 2nd and 4th Line statement generate lines which go outside
          'of the circle).
    
          Dim N As Integer, X As Integer, Y As Integer
          N = 5
          X = 0
          Y = 0
    
          Form1.ScaleMode = 0 'User
          Form1.ScaleHeight = -3
          Form1.ScaleWidth = 3
          Form1.ScaleLeft = -1.5
          Form1.ScaleTop = 1.5
    
          Circle (x, y), 1, QBColor(n)
          Line (x, y)-(1, 0), QBColor(n)
          Line (x, y)-(0, 1), QBColor(n)      '** line 2
          Line (x, y)-(-1, 0), QBColor(n)
          Line (x, y)-(0, -1), QBColor(n)     '** line 4
       End Sub
    
    

  4. Start the program by choosing Start from the Run menu or by pressing the F5 key.

  5. Click the Command1 button. Then click the Command2 button. Note that the lines in the circle generated by the Command1 click event exactly equal the radius, but the lines in the circle generated by the Command2 click event do not.


Additional reference words: 4.00 vb4win vb4all
KBCategory: kbgraphic kbprg kbprb
KBSubcategory: PrgOther


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 30, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.