我的设想:
Public Interface IDoSomething
Event AddFilter()
模式弹出窗口实现界面和贴花事件:
Public Class frmPopup Implements IDoSomething
Public Event AddFilter() Implements IDoSomething.AddFilter
RaiseEvent AddFilter()
基本主窗体包含发现和启动实现指定接口的弹出窗体的代码。
应用程序中的表单启动弹出窗口(实现接口)并处理它触发的任何事件。因此,我在表格中有以下代码:
Public Class frmMyForm
Public WithEvents m_Popup As IDoSomething
Public Sub m_Popup_AddFilter() Handles m_Popup.AddFilter
MsgBox("I'm in")
End Sub
Public Function GetBusinessObjectUsingPopup(Of O, F As IBusinessObjectSelector)
(ByRef dicPropertyValues As Dictionary(Of String, Object),
Optional ByVal titleText As String = "")
As O Implements IBaseMasterForm.GetBusinessObjectUsingPopup
Dim objBusinessObjectSelector As IBusinessObjectSelector = GetPopup(Of F)(False)
objBusinessObjectSelector.InitialiseForm()
' Activate and show the dialog
If objBusinessObjectSelector.ShowPopup() <> Windows.Forms.DialogResult.OK Then
' The user cancelled the load, so just exit
Return Nothing
End If
GetBusinessObjectUsingPopup = CType(objBusinessObjectSelector.SelectedBusinessObject, O)
End Function
和弹出代码:
Public Function GetPopup(Of F As IBasePopupChildForm)
(Optional ByVal initialisePopupPriorToReturn As Boolean = True) As F
Implements IBaseMasterForm.GetPopup
Dim lstIBasePopupChildForm As List(Of F) = GetInterfaces(Of F)()
lstIBasePopupChildForm(0).MyIBaseMasterForm = Me
If initialisePopupPriorToReturn Then
lstIBasePopupChildForm(0).InitialiseForm()
End If
Return lstIBasePopupChildForm(0)
End Function
注意-GetInterfaces(Of F)()只是扫描程序集并返回实现所需接口的表单列表。一些验证已经被截断,如果找到实现该接口的多个表单,则返回消息。