|
-
Sep 25th, 2003, 02:49 PM
#1
Thread Starter
Member
Dynamic Create ToolBarButtons
I created a dynamic toolbar like hereunder:
private sub createbuttons()
-----------------------------------
Dim tbutton As ToolBarButton
For Each menuitem In menulist
tbutton = New ToolBarButton()
...
...
AddHandler tlbPackages.ButtonClick, AddressOf DynButtonClick
tbrMenu.Buttons.Add(tbutton)
Next
Private Sub DynButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs)
----------------------------------------------------------------------------------
MessageBox.Show(e.Button.Text)
Problem:
I created a handler for buttonclick. It seems to work fine and so it is. BUT when I click on the button de "DynButtonClick" will be executed 6 times and I will see the message multiple times.
What am I doing wrong ???
PLease Help
Thanks in advanced
AXH
-
Sep 26th, 2003, 07:04 AM
#2
Hi.
Dim tbutton As ToolBarButton
For Each menuitem In menulist
tbutton = New ToolBarButton()
...
...
AddHandler tlbPackages.ButtonClick, AddressOf DynButtonClick
tbrMenu.Buttons.Add(tbutton)
Next
I assume that tlbPackages is the toolbar itself, so maybe you should remove
the Addhandler alltogether?!?. I think the problem is that you add six handlers to
the same event. I don't think you need to add a handler to a toolbarbutton, because
the toolbar uses the same events for all buttons.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Sep 26th, 2003, 07:52 AM
#3
Thread Starter
Member
I know the answer. The addhandler you have to define outside the loop and then it is working.
By the way Thanks
AXH
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|