【发布时间】:2020-07-02 05:18:07
【问题描述】:
我正在使用表单来激活应用程序的事件,并且我想将此事件中的值传递到该表单上的文本框。但它不会将该值添加到其文本框中。在这种情况下请指导我。
'模块中的代码
Public Module InventorEvents
Private WithEvents m_onDocumentChangeEvent As Inventor.ApplicationEvents
Private WithEvents m_appEvents As Inventor.ApplicationEvents
Private g_inventorApplication As Inventor.Application
Private DocumentObject As Inventor.Document
Public Sub ActiveEvents()
g_inventorApplication = Marshal.GetActiveObject("Inventor.Application")
DocumentObject = g_inventorApplication.ActiveDocument
m_onDocumentChangeEvent = g_inventorApplication.ApplicationEvents
m_appEvents = g_inventorApplication.ApplicationEvents
End Sub
Private Sub m_onDocumentChangeEvent_OnDocumentChange(ByVal DocumentObject As Inventor.Document,
ByVal BeforeOrAfter As EventTimingEnum,
ByVal ReasonsForChange As CommandTypesEnum,
ByVal Context As NameValueMap,
ByRef HandlingCode As HandlingCodeEnum) Handles m_onDocumentChangeEvent.OnDocumentChange
If BeforeOrAfter = EventTimingEnum.kAfter Then
Call _formCommands.AddText($"OnActivateDocument : {DocumentObject.DisplayName}")
End If
End Sub
End Module
'表单中的代码
Public Class _formCommands
Private Sub _formCommands_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Call InventorEvents.ActiveEvents()
End Sub
Public Sub AddText(str As String)
_tboxStatus.AppendText(str + System.Environment.NewLine)
End Sub
End Class
【问题讨论】:
-
文本是否以
TextBox结尾不应该是您确定这里发生的事情的方式。您是开发人员,而不是用户。表现得像一个人。使用调试器来观察您的代码的运行情况。您的模块中的事件处理程序是否已执行? -
如果引发事件并且执行了 AddText 调用,那么我猜问题在于您指的是模块中该表单类型的默认实例和您的实例重新实际查看的不是默认实例。
标签: .net vb.net forms winforms class