|
下载了书中的例子学习,
发现其中选择集都用到了timer控件,代码附在下面。其实不用timer控件其实也可以进行选择和处理的啊。
问题是,为什么要用timer控件?有什么优点?请懂的兄弟帮忙解答!
我曾经写过一个处理块的程序,当块对象很多的时候,有时候会有个别块没有被处理。
再运行一次程序就处理完了,timer是否为了保证对所有对象的充分完全处理?
///////////////////////////////////////////
Private Sub Command3_Click()
Dim newstr As String
If Not boo Then
MsgBox "请先生成autocad程序对象", vbOKOnly, "autocad程序对象?"
Exit Sub
End If
newstr = "测量控制点图层上的对象查询" + Chr(13) + Chr(10)
newstr = newstr + "编号 对象名称 对象句柄" + Chr(13) + Chr(10)
Text1.Text = newstr
Text1.SelStart = Len(Text1.Text)
If obj_ModelSpace.Count 0 Then
total = 0
num = 0 '计数从0开始
sum = obj_ModelSpace.Count '获得模型空间上的图形对象的数量
Text2.Text = Str(sum)
Timer2.Enabled = True '利用时间控件的事件开始获取图形对象
Else
MsgBox "当前模型空间上没有对象存在!", vbOKOnly, "工程1!"
End If
End Sub
////////////////////////////////////////////////////////////////
Private Sub Timer2_Timer()
Dim obj_entity As Object
Timer2.Enabled = False
Set obj_entity = obj_ModelSpace.Item(num)
If obj_entity.layer = "测量控制点" Then '判断,只列出在"测量控制点"图层上的对象
total = total + 1
Text1.SelText = Str(num) + " " + obj_entity.EntityName + " " + obj_entity.Handle + Chr(13) + Chr(10)
End If
num = num + 1 '每运行一次,编号加1
Text2.Text = Str(sum - num)
If num = sum Then '如果计数等于对象总数即停止
Text2.Text = Str(total)
Exit Sub
End If
Timer2.Enabled = True '如果前面计数不等于对象总数,则时间控件再启动。这样就能获得下一个图形对象
End Sub
|
|