在vb中使用类来处理事件(帮忙看看如何修改代码)
类模块eventclassmodule里的代码:<BR>Option Explicit<BR>Public WithEvents Doc As AcadDocument<BR>Public Sub AcadDocument_ObjectModified(ByVal obj As AcadObject)<BR> MsgBox "A " & TypeName(object) & " was just modified!"<BR>End Sub窗体模块中的代码:<BR>Option Explicit<BR>Dim acadApp As AcadApplication<BR>Dim X As New EventClassModule
Private Sub Form_Load()<BR> On Error Resume Next<BR> Set acadApp = GetObject(, "AutoCAD.Application")<BR> If Err Then<BR> Err.Clear<BR> Set acadApp = CreateObject("AutoCAD.Application")<BR> If Err Then<BR> MsgBox ("²»ÄÜÔËÐÐAutoCAD2004,Çë¼ì²éÊÇ·ñ°²×°ÁËAutoCAD2004")<BR> Exit Sub<BR> End If<BR> End If<BR> acadApp.Visible = True<BR> acadApp.WindowState = acMax
<BR> X.Doc = AcadApplication.ActiveDocument<BR> Dim lineObj As AcadLine<BR> Dim startPoint(0 To 2) As Double<BR> Dim endPoint(0 To 2) As Double<BR> <BR> startPoint(0) = 1#: startPoint(1) = 1#: startPoint(2) = 0#<BR> endPoint(0) = 5#: endPoint(1) = 5#: endPoint(2) = 0#<BR> <BR> Set lineObj = AcadApplication.ActiveDocument.ModelSpace.AddLine(startPoint, endPoint)<BR> <BR> Me.Hide<BR> End Sub
请教如何改动,才能够在改动直线时,触发事件?<BR>谢谢指教。 vb里做事件比较痛苦,为什么不用VBA呢?
页:
[1]