Article Preview
Buy Now
FEATURE
Quick Tip
Toolbars are "special", so you need to subclass them differently
Issue: 18.6 (November/December 2020)
Author: Markus Winter
Author Bio: Markus is a Molecular Biologist who taught himself REALbasic programming in 2003 to let the computer deal with some exceedingly tedious lab tasks. Some call it lazy, he thinks it smart. He still thinks of himself as an advanced beginner at best.
Article Description: No description available.
Article Length (in bytes): 4,722
Starting Page Number: 82
Article Number: 18606
Resource File(s):
project18606.zip Updated: 2020-11-02 09:51:25
Related Link(s): None
Excerpt of article text...
I saw a post on the Xojo forum (https://forum.xojo.com/t/event-definition-for-dummies-me/29133/15) basically asking how to show the mouse coordinates when the mouse is in a
Toolbar
. Now althoughToolbar
inherits fromRectControl
, it has no mouse-related events (due to limitations of the operating system, according to the Xojo documentation). So how can we do it?Michel Budjaret graciously provided a great example showing the use of custom events on a custom
Toolbar
class (see Figure 1).While everything is nicely contained in an OOP way, there was just one problem: creating a subclass in the usual way by adding a new class from the
insert
menu to the project and setting its super toToolbar
results in aToolbar
that does not display theToolbar
editor (where you can addToolbar
buttons to theToolbar
).You can add all your buttons and icons via code. Now while it is not too difficult to add the
Toolbar
buttons in code, most people prefer to have a visual representation of theToolbar
in their app (see Figure 2), so they add a standardToolbar
from the menu into their project.But if you do that, you can't customize that
Toolbar
with custom events. So to keep the ability to design theirToolbar
visually, users have to add all that custom code and properties to the Window which makes it look a bit messy (see Figure 2b).Do we really have to choose between clean object-oriented code and the ability to design our
Toolbar
visually?
...End of Excerpt. Please purchase the magazine to read the full article.