传递未经实例化的发件人的事件处理程序

时间:2010-11-23 15:45:46

标签: vb.net winforms devexpress

我正在创建按钮并为它们创建事件处理程序。当代码运行时,一切正常,只要成功填充菜单即可。当我单击一个按钮时,事件将触发,但sender = Nothing并且Object未设置为实例异常。有任何想法吗?一定是遗漏了什么。

Imports DevExpress.XtraBars.Ribbon

Public Class Form1

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim menu As New RibbonControl
        Dim aPage As New RibbonPage("Nicks Page")
        'groups'
        Dim aGroup1 As New RibbonPageGroup("1st Group")

        'ADD BUTTONS TO RIBBON GROUP HERE'
        Dim i As New DevExpress.XtraBars.BarButtonItem()
        i.Caption = "Nicks Button"
        AddHandler i.ItemClick, AddressOf y
        aGroup1.ItemLinks.Add(i)

        Dim i2 As New DevExpress.XtraBars.BarButtonItem()
        i2.Caption = "Nicks Other Button"
        AddHandler i2.ItemClick, AddressOf y
        aGroup1.ItemLinks.Add(i2)

        aPage.Groups.Add(aGroup1)
        menu.Pages.Add(aPage)
        Me.Controls.Add(menu)
    End Sub

    Private Sub y(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs)
        'EXCEPTION SENDER=NOTHING MSGBOX FAILS'
        MsgBox(CType(sender, DevExpress.XtraBars.BarButtonItem).Caption)
    End Sub
End Class

1 个答案:

答案 0 :(得分:1)

发件人是BarManager。请改用e.Item。