我是一名 C# 程序员,并制作了一个 C# 库来处理 tcp/ip 聊天。现在我有必要从 Server VB Winform 程序中使用它。我很确定这是一个简单的解决方案问题,但我已经挣扎了好几天。所以在 C# 我有那个类:
public class AsynchronousServer
{
public AsynchronousServer()
{
}
public delegate void ChangedEventHandler(string strMessage);
public static event ChangedEventHandler OnNotification;
public static event ChangedEventHandler OnAnswerReceived;
...
}
现在我必须专注于服务器程序:如果那个 VB 程序是在 C# 中,我会编写下面的代码,用于通过单击按钮连接服务器
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void btnStart_Click(object sender, RoutedEventArgs e)
{
AsynchronousServer.OnNotification += AsynchronousServer_OnNotification;
AsynchronousServer.OnAnswerReceived += AsynchronousServer_OnAnswerReceived;
AsynchronousServer.StartServer(tbxIpAddress.Text,tbxPort.Text);
}
VB中的相同程序:
Imports SocketLibrary
Public Class Form1
Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
AsynchronousServer.OnNotification <--- member not present
AsynchronousServer.OnAnswerReceived <--- member not present
AsynchronousServer.StartServer(tbxIpAddress.Text, tbxPort.Text);<-----OK
End Sub
End Class
问题是成员 AsynchronousServer.OnNotification 根本不存在,所以我无法添加事件。我知道我可能需要添加 WithEvents 关键字,但我可能无法成功。
简而言之,我必须将该 VB winform 程序连接到我无法从 VB 类中看到的 C# 库事件。
摇曳的蔷薇
相关分类