在用户控件中创建的事件不起作用

时间:2014-04-19 07:21:54

标签: c# vb.net events user-controls

当您将工具置于UserControl中时,不会从事件窗口内部激活

UserControl中的代码:

 Public Class Commands

    Event Clicks(sender As Object, e As EventArgs)

    Private Sub Button1_ClickEvent(sender As Object, e As EventArgs) Handles Button1.ClickEvent
          msgbox "Is Work In UserControl"
          RaiseEvent Clicks(sender, e)

    End Sub

表格中的代码:

Private Sub Commands1_Click(sender As Object, e As EventArgs) Handles Commands1.Clicks
    MsgBox("No Work IN Form")

End Sub

1 个答案:

答案 0 :(得分:0)

尝试将事件声明为公开

Public Event Clicks(sender As Object, e As EventArgs)

这使得事件可以从用户控件外部看到,因此您可以从表单中对其做出反应。