0

我是 Visual Basic 的新手,我想编写多个按钮,这些按钮具有相似的功能,并且想为每个按钮添加相同的脚本,但它会给每个按钮提供很多行,那么相同的脚本如何,我想要能够将外部链接作为“.VB”与基本程序链接进行通信......例如:

(主窗口代码)“JoVen.vb”

Public Sub Button1_Click (ByVal sender As System.Object, ByVal e As
    'Code to send run External link Ai.vb
End Sub

Public Sub Button2_Click (ByVal sender As System.Object, ByVal e As
    'Code to send run External link Ai.vb
End Sub

(代码外部VB脚本)“AI.vb”

Public Class AI
    Public Sub Main ()
         Dim But1 The New Jove ()
         But1.Bt1 = True
         MsgBox ("Link Executed")
    end Sub
end Class

我希望你能理解我,如果我写错了,对不起,我正在使用谷歌翻译。

4

2 回答 2

0

嗨,您可以在对象过程结束时使用句柄,例如

Public Sub Button_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click
于 2013-08-30T05:27:40.493 回答
0

您可以让多个按钮控件由同一个单击事件处理程序处理,如下所示:

Public Sub Button_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click
    ' Common code that all buttons need here
Dnd Sub

现在您不必为一堆按钮单击事件处理程序“重复”逻辑。

于 2013-08-30T04:11:14.537 回答