Dynamic toolbutton

Hi,

I added a toolbutton to a toolbar programmatically. When running the app, and clicking that toolbutton, the Action event of the toolbar will not respond. Is that normal behavior or a bug?

Thanks,
Payam

What is your code? Adding code dynamically definitely calls the Toolbar Action event handler when the button is clicked.

Hi,

My code is this:

SmsDownButton=New ToolButton
SmsDownButton.Style=ToolButton.ToolStyleDropDown
SmsDownButton.Caption=“Message”
SmsDownButton.Icon=SendMessage

Dim smsMenu as New MenuItem

Dim smsSend as New MenuItem
Dim smsSeparator as New MenuItem

SmsDownButton.Name=“Menu Message”
smsSend.Text=“Send…”
smsSeparator.Text=MenuItem.TextSeparator

smsMenu.Append smsSend
smsMenu.Append smsSeparator

SmsDownButton.DropDownMenu=smsMenu

Me.Append SmsDownButton

A button with a DropDownMenu calls the DropDownMenuAction event handler with the details of the button that was pressed and the menu item that was selected.

For more information about Toolbars, refer to User Guide Book 2: User Interface, Chapter 2: Desktop, Section 14: Toolbars.

Yes this is a button with a DropDownMenu, which I did not create from the IDE graphical interface. The Toolbar has not that toolbutton, but the toolbutton is added to it during runtime. I am sorry, but the action event handler is not called when clicking that button from the toolbar during runtime. I wanted to know if my code is wrong or if it’s a bug. If it’s a bug I will send a report to feedback.

I looked at the section you mentioned in User’s Guide. I did not find any answer to this problem.

Thanks,
Payam

The ACTION event won’t be called or raised
The tool button is a menu so when you select an item in the drop down menu the DROP DOWN MENU ACTION will be raised
Add that event to the tool bar & put a break statement in the event and you’ll see it

The Toolbar is refreshed every 10 seconds for some reason. If I click the toolbutton I need something to respond to that click in order to prevent the refresh of the Toolbar. Why? because clicking that button pops up the menu, and while the menu shows, the Toolbar could be refreshed. In this way, the toolbutton loses the grip, so to speak, from the menu, which provokes a crash, something like Bad Sig Exec Kernel, or the like. That is why I really needed something to react to that toolbutton click. But you say this is normal behavior not a bug. So there is no solution to it?

The toolbar doesn’t rebuild itself so I’m not sure why that would be happening in your case
The framework doesn’t rebuild it

Yes it does if you write Toolbar1.Refresh in Timer1 for example. The timer refreshes the toolbar every 10s. I swear the toolbar rebuilds :slight_smile:

Why would you do that ?

Okay :slight_smile: I do that because the toolbar plays the role of a mail inbox. When it rebuilds, it’s because the toolbutton must signal that there is a message. So it changes the icon, displaying 1 or 2 or 3, etc. And it also adds the name of the sender to the dropdownmenu.

That’s weird, I know. But it’s a very beautiful and very practical gadget :slight_smile:

refresh it only when there IS new mail not every 10ms
every 10ms means you won’t be able to actually use it - like you’ve encountered

secondly dont “refresh” use invalidate - it then only redraws when it needs to
invalidate basically says “when you redraw things redraw this as well”

I have a sample if you want it
PM me with an email address

Yes, you are right. I will change the method. Still a crash could occur, but the chances for this to happen are minimal.

Thank you!

If you want this sample app email me - norman@xojo.com
Its not gorgeous code but it illustrates how to update the icon on a toolbar member while a user is actually using the toolbar