亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將 C# 庫中的事件觸發到 VB Winform 程序中

將 C# 庫中的事件觸發到 VB Winform 程序中

C#
江戶川亂折騰 2021-10-24 19:36:40
我是一名 C# 程序員,并制作了一個 C# 庫來處理 tcp/ip 聊天?,F在我有必要從 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 SubEnd Class問題是成員 AsynchronousServer.OnNotification 根本不存在,所以我無法添加事件。我知道我可能需要添加 WithEvents 關鍵字,但我可能無法成功。簡而言之,我必須將該 VB winform 程序連接到我無法從 VB 類中看到的 C# 庫事件。
查看完整描述

2 回答

?
搖曳的薔薇

TA貢獻1793條經驗 獲得超6個贊

我假設您從未使用過 VB,因此會回答您:
您需要使用AddHandler

AddHandler AsynchronousServer.OnNotification, AddressOf YourMethod

順便說一句,恕我直言,靜態事件非常糟糕。


查看完整回答
反對 回復 2021-10-24
  • 2 回答
  • 0 關注
  • 254 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號