我正在尝试在我正在开发的小型winforms应用中实现MVP。
已知,我需要定义一个IView
接口。
IView
接口应具有混凝土View
加载时发射的事件。
此事件已经在Winforms中作为Load()
事件植入。
现在在一些指南/教程中,我看到他们像这样实现了
Public Interface IView
Event OnPrepareView()
.....
End Interface
Public Class MainForm
Inherits Form
Implements IView
Private Sub Main_Load(sender As Object, e As EventArgs) Handles Me.Load
RaiseEvent OnPrepareView()
End Sub
Public Event OnPrepareView()
End Class
现在,我想知道是否可以直接在接口中直接暴露表单Load
事件,因此IView
看起来像:
Public Interface IView
Event Load()
.....
End Interface
和加载事件以其load
事件的形式实现。
如果可能的话,我该如何在VB中进行?
update
例如,对于Icon
或诸如Show
之类的属性,该属性在System.Windows.Forms.Form
中定义。
我将有一个IView
:
Public Interface IView
Property Icon as Icon
Sub Show()
End Interface
,然后在我的具体实施中
Public Class FooForm
Inherits Form
Implements IView
Public Overloads Property Icon as Icon Implementes IView.Icon
Get
return MyBase.Icon
End Get
Set
MyBase.Icon = value
End Set
Public Overloads Sub Show()
MyBase.Show()
End Sub
End Class
但是我该如何处理表单事件?
我应该在IView
中声明新事件,例如:
Public Interface IView
Property Icon as Icon
Sub Show()
Event OnLoad()
End Interface
Public Class FooForm
Inherits Form
Implements IView
....
....
Public Event OnLoad() Implements IView.OnLoad
Private Sub FooForm_Load() Handles Me.Load
RaiseEvent OnLoad()
End Sub
End Class
您应该在接口中声明事件,然后在Form
中实现接口,然后覆盖OnLoad
并提高事件。例如:
Public Interface IView
Event Load As EventHandler
End Interface
Public Class Form1
Implements IView
Public Shadows Event Load As EventHandler Implements IView.Load
Protected Overrides Sub OnLoad(e As EventArgs)
MyBase.OnLoad(e)
RaiseEvent Load(Me, e)
End Sub
End Class