我想在 VB.NET WinForms 应用程序中重用类后面的 ASP.NET Web 应用程序代码中有一些代码。请从后面的代码中查看下面的代码(ASP.NET Web 应用程序(不是网站)):
Public Class _Default
Inherits System.Web.UI.Page
Private Sub button1_Click(sender As Object, e As System.EventArgs) Handles button1.Click
MsgBox("button1.click")
End Sub
End Class
以及背后的代码:
Imports WebApplication1
Public Class TestClass
Public Shared Sub Test100()
MsgBox("button clicked on page")
End Sub
End Class
Public Class Form1
Public Event BellRings(ByVal sender As Object, ByVal e As EventArgs)
Public test As String
public Shared TestMethod()
MsgBox("Test Method was called")
End public
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Try
Dim d As WebApplication1._Default = New WebApplication1._Default
AddHandler d.button1.Click, AddressOf Form1.TestMethod
Catch ex As Exception
End Try
End Sub
End Class
我意识到创建一个两个客户端都使用的服务层可能会更好,但是如果上述方法可能的话,我会徘徊吗?即是否可以在 WinForm 中为 Web 应用程序中的事件(即 button.click)添加事件处理程序?