home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / PVb5.0 / VB / SAMPLES / PGUIDE / PROGWOB / PWORECT.CLS < prev    next >
Encoding:
Visual Basic class definition  |  1997-01-29  |  5.2 KB  |  177 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Rectangle"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Option Explicit
  11. ' >>╫ε║├╘┌í░╚½─ú┐Θ▓Θ┐┤í▒─ú╩╜╧┬╘─╢┴íú<<
  12. '
  13. ' ┤µ┤ó╡≈╩╘▒Ω╩╢║┼íú
  14. Private mlngDebugID As Long
  15. Implements IDebug
  16.  
  17. ' Rectangle ╩╡╧╓┴╜╕÷╜╙┐┌ú║
  18. '   ╘┌╫╘╝║╡─╜╙┐┌╔╧╙╨╥╗╕÷╩⌠╨╘ (Filled) ║═╥╗╕÷╖╜╖¿ (TimeTest)íú
  19.  
  20. Implements IShape
  21. Implements Polygon
  22.  
  23. ' ─┌▓┐╡─ Polygon ╢╘╧≤╩╡╝╩╔╧▒ú┤µ╩²╛▌▓ó═Ω│╔╥╗╨⌐╣ñ╫≈íú
  24. '   Rectangle ▒ú│╓╢╘ Polygon ╜╙┐┌║═─┌▓┐ Polygon ╡─ IShape ╜╙┐┌╡─╥²╙├íú
  25. Private mpyg As Polygon
  26. Private mish As IShape
  27.  
  28. ' ▒ú┤µ Color ╩⌠╨╘ (Polygon ╜╙┐┌╩╡╧╓)íú
  29. Private mrgbColor As Long
  30.  
  31. ' ▒ú┤µ Filled ╩⌠╨╘ (╘┌ Rectangle ╡─╚▒╩í╜╙┐┌)íú
  32. Private mblnFilled As Boolean
  33.  
  34. ' -------------------------------------
  35. ' ╒Γ╩╟ IShape ╜╙┐┌╡─ Rectangle ╡─╩╡╧╓╣²│╠╡─┐¬╩╝íú
  36.  
  37. ' IShape. ╡≈╙├ DrawToPictureBox ╗¡╢α▒▀╨╬ú¼
  38. ' ======       ----------------   ╦∙╥╘├┐╕÷─ú╨═╡─└α▒╪╨δ╠ß╣⌐╞Σ╫╘╝║╡─╩╡╧╓╣²│╠íú
  39. '
  40. Private Sub IShape_DrawToPictureBox(ByVal pb As PictureBox)
  41.     ' ╙δ─┌▓┐ Polygon ╡─ IShape ╜╙┐┌╧α▒╚╜╧ú¼
  42.     '   └√╙├ Rectangle ╡─╙┼╩╞╘┌╙┌╦ⁿ╙╨╗¡┐≥╡─═╝╨╬├ⁿ┴εú¼╓╗╨Φ╥╗╕÷▓┘╫≈╢°▓╗╩╟ 4 ╕÷íú
  43.     '   (═╝╨╬▒╗╚╧╬¬╩╟╫ε╖╤╩▒╝Σ╡─╥╗└α▓┘╫≈)
  44.     Dim sngX1 As Single, sngY1 As Single
  45.     Dim sngX2 As Single, sngY2 As Single
  46.     Call mpyg.GetPoint(0, sngX1, sngY1)
  47.     Call mpyg.GetPoint(1, sngX2, sngY2)
  48.     If mblnFilled Then
  49.         pb.Line (sngX1, sngY1)-(sngX2, sngY2), mrgbColor, BF
  50.     Else
  51.         pb.Line (sngX1, sngY1)-(sngX2, sngY2), mrgbColor, B
  52.     End If
  53. End Sub
  54.  
  55. ' IShape.TimeTest ╖╜╖¿╙├└┤╧╘╩╛╝╕╕÷└α╩╡╧╓╡─╥╗╕÷╜╙┐┌╓╨╡≈╙├╡─╖╜╖¿╡─╝⌡╔┘╡─╡≈╙├┐¬╧·ú¼
  56. ' ====== --------
  57. '   -- ╧α╢╘╙┌╘┌└α╡─╚▒╩í╜╙┐┌╡≈╙├└α╦╞╡─╖╜╖¿íú
  58. '
  59. Private Sub IShape_TimeTest()
  60. End Sub
  61.  
  62. ' -------------------------------------
  63. ' ╒Γ╩╟ Polygon ╜╙┐┌╡─╩╡╧╓╣²│╠┐¬╩╝íú
  64.  
  65. ' Polygon.Color - ╙╔╙┌─┌▓┐ Polygon ▓╗╙├╙┌╗¡╛╪╨╬ú¼
  66. ' ======= -----   Color ╩⌠╨╘═Ω╚½▒╗╕▓╕╟íú
  67. '   ╒Γ▓╗╩╟▒╪╨δ╡─ú╗Rectangle ┐╔╥╘░╤▒ú┤µ╡─ Color ╩⌠╨╘╕│╓╡╕°─┌▓┐ Polygon(╧±└α Triangle ╦∙╫÷╡─)ú¼
  68. '   ▒ú┤µ╩╡╧╓┤·┬δ║═┤µ┤ó┐╒╝Σíú
  69. '   ╤╒╔½╓╡┐╔╥╘╘┌╗¡╡─╣²│╠╓╨┤╙─┌▓┐ Polygon ┤ª╡├╡╜íú
  70. Private Property Get Polygon_Color() As Long
  71.     Polygon_Color = mrgbColor
  72. End Property
  73. '
  74. Private Property Let Polygon_Color(ByVal RHS As Long)
  75.     If 0 <> (RHS And &HFF000000) Then
  76.         Err.Raise vbObjectError + 2080, , _
  77.             "Polygon ╡─╬▐╨º╤╒╔½╓╡íú"
  78.         Exit Property
  79.     End If
  80.     mrgbColor = RHS
  81. End Property
  82.  
  83. ' Polygon.TimeTest - Rectangle ╙╨╚²╕÷ TimeTest ╖╜╖¿ú¼
  84. ' ======= --------
  85. '   ╥╗╕÷╘┌ IShape ╜╙┐┌ (╙├╙┌╧╘╩╛╢α╠¼╨╘║═╘τ╞┌░≤╢¿)ú¼
  86. '   ╥╗╕÷╘┌╦ⁿ╫╘╝║╡─╜╙┐┌ (╙├╙┌╧╘╩╛║≤╞┌░≤╢¿)ú¼║═╒Γ╥╗╕÷íú
  87. '   ╒Γ╥╗╕÷╩╟ Rectangle ╩╡╧╓ Polygon ╜╙┐┌╡─ú╗
  88. '   ╦ⁿ▓╗╙├╙┌╞Σ╦√╚╬║╬╡╪╖╜íú
  89. Private Sub Polygon_TimeTest()
  90. End Sub
  91.  
  92. ' Polygon.GetPoint
  93. ' ======= --------
  94. '
  95. Private Sub Polygon_GetPoint(ByVal intPoint As Integer, X As Single, Y As Single)
  96.     ' ╕°─┌▓┐ Polygon ╕│╓╡íú
  97.     Call mpyg.GetPoint(intPoint, X, Y)
  98. End Sub
  99.  
  100. ' Polygon.GetPointCount
  101. ' ======= -------------
  102. '
  103. Private Property Get Polygon_GetPointCount() As Integer
  104.     ' ╥≥╬¬╫▄╩╟╙├┴╜╕÷╡π╛÷╢¿╥╗╕÷╛╪╨╬ú¼╒Γ└∩├╗╙╨╥¬╕│╓╡╕°─┌▓┐ Polygon ╡─╡π
  105.     Polygon_GetPointCount = 2
  106. End Property
  107.  
  108. ' Polygon.SetPoints - ╡▒╩╡╧╓ Polygon ╜╙┐┌╡─ SetPoints ╖╜╖¿╩▒ú¼
  109. ' ======= ---------     Rectangle ╓┤╨╨╫╘╝║╡─┤·┬δú¼
  110. '   ╚╖▒ú╩Σ╚δ╩²╫Θ╓╗░ⁿ└¿┴╜╕÷╡π (4 ╕÷ Single ╨═)ú¼
  111. '   ▓ó╕│╓╡╕°─┌▓┐ Polygon ╢╘╧≤íú
  112. Private Sub Polygon_SetPoints(asngPoints() As Single)
  113.     Dim blnBadArray As Boolean
  114.     On Error Resume Next
  115.     ' ▒ú╓ñ╩Σ╚δ╩²╫Θ░ⁿ└¿▓╗│¼╣² 4 ╕÷╡πíú
  116.     '   (Polygon ╡─ SetPoint ╖╜╖¿╥¬▒ú╓ñ╩²╫Θ╧┬▒Ω┤╙ 0 ┐¬╩╝íú)
  117.     If UBound(asngPoints) <> 3 Then blnBadArray = True
  118.     ' ╚τ╣√╡≈╙├ UBound ╩▒│÷┤φú¼═╦│÷╩²╫Θíú
  119.     If Err.Number <> 0 Then blnBadArray = True
  120.     If blnBadArray Then
  121.         Err.Raise vbObjectError + 2083, , _
  122.             "╥╗╕÷╛╪╨╬╥¬╙╔╧┬▒Ω┤╙ 0 ┐¬╩╝╡─╩²╫Θ╡─ 4 ╕÷╩² (left, top, right, bottom) ╓╕╢¿íú"
  123.         Exit Sub
  124.     End If
  125.     ' ╔Φ╓├─┌▓┐ Polygonú¼═Ω│╔╤Θ╓ñ╩²╫Θ▓ó▒ú┤µíú
  126.     Call mpyg.SetPoints(asngPoints)
  127. End Sub
  128.  
  129. ' --------------------------------------
  130. ' ╒Γ╩╟ Rectangle ╢╘╧≤╡─╚▒╩í╜╙┐┌╡─┐¬╩╝íú
  131.  
  132. ' TimeTest ╖╜╖¿╬▐▓╬╩²ú¼▓╗╫÷╚╬║╬▓┘╫≈ú¼╢°╟╥┴ó╝┤╖╡╗╪íú
  133. ' --------      ╦ⁿ▒╗╙├╙┌╦╡├≈║≤╞┌░≤╢¿╡─╡≈╙├┐¬╧·ú¼
  134. '   ╧α╢╘╙┌╘┌ IShape ╜╙┐┌╡≈╙├ TimeTest ╦∙╠ß╣⌐╡─╘τ╞┌░≤╢¿íú
  135. Public Sub TimeTest()
  136. End Sub
  137.  
  138. ' Filled ╩⌠╨╘╛÷╢¿╩╟╖±╘┌╗¡╩▒╠ε│Σ╛╪╨╬íú
  139. ' ------
  140. Public Property Get Filled() As Boolean
  141.     Filled = mblnFilled
  142. End Property
  143. '
  144. Public Property Let Filled(ByVal NewValue As Boolean)
  145.     mblnFilled = NewValue
  146. End Property
  147.  
  148. ' --------------------------------------
  149. ' ╒Γ╩╟└α╡─╦╜╙╨╣²│╠┐¬╩╝ (╕¿╓·╣²│╠╝░╩┬╝■╣²│╠)íú
  150.  
  151. Private Sub Class_Initialize()
  152.     Dim asngPoints(0 To 3) As Single
  153.     ' ╡≈╩╘┤·┬δíú
  154.     mlngDebugID = DebugInit(Me)
  155.     '
  156.     ' ┤┤╜¿─┌▓┐╡─ Polygon ╢╘╧≤ú¼▓ó╗±╡├╢╘ IShape ╜╙┐┌╡─╥²╙├íú
  157.     Set mpyg = New Polygon
  158.     Set mish = mpyg
  159.     ' │⌡╩╝╗»─┌▓┐ Polygoníú
  160.     Call mpyg.SetPoints(asngPoints)
  161. End Sub
  162.  
  163. Private Sub Class_Terminate()
  164.     DebugTerm Me
  165. End Sub
  166.  
  167. ' -------- IDebug ╩╡╧╓ --------
  168. '
  169. ' IDebug.DebugID ╧≥─·╠ß╣⌐╥╗╓╓╩╢▒≡╢╘╧≤╡─╖╜╖¿íú
  170. ' ====== -------    ╦ⁿ╩╟ modFriend ╓╨╔∙├≈╡─ DebugInitíóDebugTerm
  171. '   ║═ DebugShow ╡≈╩╘╣²│╠╦∙╥¬╟≤╡─íú
  172. '
  173. Private Property Get IDebug_DebugID() As Long
  174.     IDebug_DebugID = mlngDebugID
  175. End Property
  176.  
  177.