传递未实例化的发送者的事件处理程序
我正在动态创建按钮并为它们创建事件处理程序。当代码运行时,一切工作正常,只要成功地动态填充菜单即可。当我单击按钮时,事件会触发,但 sender=Nothing 且对象未设置为实例异常出现。有什么想法吗?一定是缺少了什么。
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
I am creating buttons on the fly and creating event handlers for them. When the code runs everything works fine as far as populating the menu on the fly successfully. When I click a button the event fires, but sender=Nothing and the Object is not set to instance exception comes up. Any Ideas? Must be missing something.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发送者是BarManager。请改用 e.Item。
The sender is the BarManager. Use e.Item instead.