I am writing a VS .NET Addin and I need to create menu items
(CommandBarButt ons) at run-time. I can do that but the event handlers
do not work. They are registered using AddHandler (wich was created
for that, isn't it?), but I think I am using it wrongly, because only
the last registered button fires the event and only if it the button
variable is declared as a class field (sorry if the term is incorrect,
I am new to VB and .NET).
Any solution in C# or VB .NET is welcome. I actually started writing
the Addin in C# but changed to VB because the C# code couldn't fire
events. Events could be fired in VB using the Handles clause but now I
need to add handlers at runtime...
My Code (obviously simplified):
Public Class Connect
....
Dim button As CommandBarButto n 'button as class field
Private Sub GuiInit()
...
For Each filestr In files
button =
myMenu.Controls .Add(MsoControl Type.msoControl Button)
button.Caption = Path.GetFileNam e(filestr)
button.Tag = filestr
AddHandler button.Click, AddressOf WizardButtonCli ck
Next
End Sub
Public Sub WizardButtonCli ck(ByVal Ctrl As CommandBarButto n, ByRef
CancelDefault As Boolean)
handler.Process File(Ctrl.Tag)
End Sub
If you don't want to post to the newsgroup, e-mail to
arrais.usenet@n nospamm.qualiti .com
(CommandBarButt ons) at run-time. I can do that but the event handlers
do not work. They are registered using AddHandler (wich was created
for that, isn't it?), but I think I am using it wrongly, because only
the last registered button fires the event and only if it the button
variable is declared as a class field (sorry if the term is incorrect,
I am new to VB and .NET).
Any solution in C# or VB .NET is welcome. I actually started writing
the Addin in C# but changed to VB because the C# code couldn't fire
events. Events could be fired in VB using the Handles clause but now I
need to add handlers at runtime...
My Code (obviously simplified):
Public Class Connect
....
Dim button As CommandBarButto n 'button as class field
Private Sub GuiInit()
...
For Each filestr In files
button =
myMenu.Controls .Add(MsoControl Type.msoControl Button)
button.Caption = Path.GetFileNam e(filestr)
button.Tag = filestr
AddHandler button.Click, AddressOf WizardButtonCli ck
Next
End Sub
Public Sub WizardButtonCli ck(ByVal Ctrl As CommandBarButto n, ByRef
CancelDefault As Boolean)
handler.Process File(Ctrl.Tag)
End Sub
If you don't want to post to the newsgroup, e-mail to
arrais.usenet@n nospamm.qualiti .com
Comment