?? object.cls
字號:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "DrawObject"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Attribute VB_Ext_KEY = "Collection" ,"DrawLine"
Attribute VB_Ext_KEY = "Member0" ,"DrawLine"
Option Explicit
'局部變量,保存集合
Private mCol As Collection
Public Function Add(DrawObject As Object, Optional sKey As String) As Object
'向集合中增加圖元
If Len(sKey) = 0 Then
mCol.Add DrawObject
Else
mCol.Add DrawObject, sKey
End If
'返回已創建的對象
Set Add = DrawObject
End Function
Public Property Get Item(vntIndexKey As Variant) As DrawLine
Attribute Item.VB_UserMemId = 0
'引用集合中的一個元素時使用。
'vntIndexKey 包含集合的索引或關鍵字,
'這是為什么要聲明為 Variant 的原因
'語法:Set foo = x.Item(xyz) or Set foo = x.Item(5)
Set Item = mCol(vntIndexKey)
End Property
Public Property Get Count() As Long
'檢索集合中的元素數時使用。語法:Debug.Print x.Count
Count = mCol.Count
End Property
Public Sub Remove(vntIndex As Variant)
'刪除集合中的元素時使用。
'vntIndex 指定需要刪除的元素
'語法:x.Remove(xyz)
Dim i As Integer
mCol.Remove vntIndex '在集合中刪除指定圖元
End Sub
Public Property Get NewEnum() As IUnknown
Attribute NewEnum.VB_UserMemId = -4
Attribute NewEnum.VB_MemberFlags = "40"
'本屬性允許用 For...Each 語法枚舉該集合。
Set NewEnum = mCol.[_NewEnum]
End Property
Private Sub Class_Initialize()
'創建類后創建集合
Set mCol = New Collection
End Sub
Private Sub Class_Terminate()
'類終止后破壞集合
Set mCol = Nothing
End Sub
Public Function IsObject(x As Long, y As Long, mOb As Object, mStyle As Long) As Long
'判斷輸入點(x,y)是否在圖元上
'該函數返回指定圖元在集合中的位置
Dim mObject As Object
Dim sta As Long
Dim i As Long
For i = 1 To mCol.Count
sta = mCol(i).IsCurrent(x, y) '判斷指定點位置
If sta > 0 Then
'指定點指向當前線段
Set mOb = mCol(i)
mStyle = sta
IsObject = i
Exit Function '退出函數
End If
Next i
Set mOb = Nothing '無圖元
mStyle = 0
IsObject = 0
End Function
Public Sub PrintObject(Drawing As Object)
'打印全部圖元
Dim mObject As Object
For Each mObject In mCol
'遍歷集合,繪制全部圖元
Call mObject.PrintObject(Drawing)
Next
End Sub
Public Sub Draw(Drawing As Object)
'繪制全部圖元
Dim mObject As Object
Drawing.Cls '清屏
For Each mObject In mCol
'遍歷集合,繪制全部圖元
Call mObject.Draw(Drawing)
Next
End Sub
Public Sub Save(File As Integer)
'保存圖元數據到文件中
Dim mObject As Object
For Each mObject In mCol
Call mObject.Save(File)
Next
End Sub
Public Sub Load(File As Integer)
'讀文件數據
Dim mObject As Object
Dim i As Integer
Do While Not EOF(File)
Input #File, i '判斷類類型
Select Case i
Case 1 '直線
Set mObject = New DrawLine
mObject.Load File
mCol.Add mObject
Set mObject = Nothing
Case 2 '矩形
Set mObject = New DrawRec
mObject.Load File
mCol.Add mObject
Set mObject = Nothing
Case 3 '矩形
Set mObject = New DrawCircle
mObject.Load File
mCol.Add mObject
Set mObject = Nothing
End Select
Loop
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -