温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

VB.NET中回调函数如何使用

发布时间:2021-07-14 14:38:15 来源:亿速云 阅读:582 作者:Leah 栏目:编程语言

VB.NET中回调函数如何使用,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

VB.NET经过长时间的发展,很多用户都很了解VB.NET回调函数了,这里我发表一下个人理解,和大家讨论讨论。创建数据库事件处理函数(VB.NET回调函数)

无论什么时候一个对象被打开并要被修改时,数据库事件处理函数会被调用。当然,如果这时我们监视的命令不是活动的,我们就应该跳过任何被这个VB.NET回调函数调用的内容。

If bEditCommand = False Then
Return
End If

同样地,如果我们监视的命令已经结束,而ObjectOpenedForModify事件被另一个VB.NET回调函数再次触发的话,而这时有对象被修改时,我们要阻止所有由这个VB.NET回调函数执行的动作。

If bDoRepositioning = True Then
Return
End If

这个VB.NET回调函数剩余部分的代码用来验证我们是否正在处理EMPLOYEE块索引。如果是的话,我们就获取它的ObjectID和位置(三维点)。下面的代码可以被粘贴到这个事件处理函数函数。

Public Sub objOpenedForMod(ByVal o As Object, ByVal e As ObjectEventArgs)  If bEditCommand = False Then  Return  End If  If bDoRepositioning = True Then  Return  End If  Dim objId As ObjectId  objId = e.DBObject.ObjectId  Dim trans As Transaction  Dim bt As BlockTable  Dim db As Database  db = HostApplicationServices.WorkingDatabase  trans = db.TransactionManager.StartTransaction()  Try  'Use it to open the current object!  Dim ent As Entity = trans.GetObject(objId, OpenMode.ForRead, False)  If TypeOf ent Is BlockReference Then 'We use .NET's RTTI to establish type.  Dim br As BlockReference = CType(ent, BlockReference)  'Test whether it is an employee block  'open its extension dictionary  If br.ExtensionDictionary().IsValid Then  Dim brExtDict As DBDictionary = trans.GetObject(br.ExtensionDictionary(), OpenMode.ForRead)  If brExtDict.GetAt("EmployeeData").IsValid Then  'successfully got "EmployeeData" so br is employee block ref  'Store the objectID and the position  changedObjects.Add(objId)  employeePositions.Add(br.Position)  'Get the attribute references,if any  Dim atts As AttributeCollection  atts = br.AttributeCollection  If atts.Count > 0 Then  Dim attId As ObjectId  For Each attId In atts  Dim att As AttributeReference  att = trans.GetObject(attId, OpenMode.ForRead, False)  changedObjects.Add(attId)  employeePositions.Add(att.Position)  Next  End If  End If  End If  End If  trans.Commit()  Finally  trans.Dispose()  End Try  End Sub

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI