home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch2 / Scale.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-03-22  |  1.7 KB  |  53 lines

  1. VERSION 5.00
  2. Begin VB.Form frmScale 
  3.    AutoRedraw      =   -1  'True
  4.    Caption         =   "Scale"
  5.    ClientHeight    =   3735
  6.    ClientLeft      =   2235
  7.    ClientTop       =   1305
  8.    ClientWidth     =   4215
  9.    LinkTopic       =   "Form1"
  10.    PaletteMode     =   1  'UseZOrder
  11.    ScaleHeight     =   -10.826
  12.    ScaleLeft       =   -1
  13.    ScaleMode       =   0  'User
  14.    ScaleTop        =   11
  15.    ScaleWidth      =   12.217
  16. Attribute VB_Name = "frmScale"
  17. Attribute VB_GlobalNameSpace = False
  18. Attribute VB_Creatable = False
  19. Attribute VB_PredeclaredId = True
  20. Attribute VB_Exposed = False
  21. Option Explicit
  22. Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
  23. Private Sub Form_Load()
  24. Dim X1 As Long
  25. Dim Y1 As Long
  26. Dim X2 As Long
  27. Dim Y2 As Long
  28. Dim scale_left As Single
  29. Dim scale_top As Single
  30. Dim pix_per_unit_x As Single
  31. Dim pix_per_unit_y As Single
  32.     ' Custom coordinates for the points.
  33.     X1 = 0
  34.     Y1 = 2
  35.     X2 = 10
  36.     Y2 = 8
  37.     ' Draw an X.
  38.     Line (X1, Y1)-(X2, Y2)
  39.     Line (X1, Y2)-(X2, Y1)
  40.     ' Prepare for translation.
  41.     scale_left = ScaleX(ScaleLeft, ScaleMode, vbPixels)
  42.     scale_top = ScaleY(ScaleTop, ScaleMode, vbPixels)
  43.     pix_per_unit_x = ScaleX(1, ScaleMode, vbPixels)
  44.     pix_per_unit_y = ScaleY(1, ScaleMode, vbPixels)
  45.     ' Translate coordinates into pixels.
  46.     X1 = X1 * pix_per_unit_x - scale_left
  47.     Y1 = Y1 * pix_per_unit_y - scale_top
  48.     X2 = X2 * pix_per_unit_x - scale_left
  49.     Y2 = Y2 * pix_per_unit_y - scale_top
  50.     ' Draw a box around the X.
  51.     If Rectangle(hdc, X1, Y1, X2, Y2) = 0 Then Exit Sub
  52. End Sub
  53.