Chapter 11. Canvases

The Canvas control class is REALbasic’s way of letting the programmer display a custom image within a window. Canvases are probably the most versatile and powerful of REALbasic’s built-in control classes, because in effect they let you build your own piece of the interface. A Canvas subclass could be used to simulate a PushButton, a StaticText, a ListBox, and many other existing classes and often is used as the basis for constructing variants on such classes.

From the programmer’s point of view, the chief sources of a Canvas’s great power and versatility are as follows:

  • A Canvas permits your code to take direct control over drawing within its region.

  • A Canvas receives both mouse movement and mouse button events.

  • A Canvas can be scrolled, and can scroll other controls along with it.

  • A Canvas can overlay another control, invisibly if desired, in such a way as to let its powers and those of the other control supplement one another.

A Canvas and a window’s background have much in common. A Canvas does not have a BackColor or a HasBackColor property, so it lacks a window’s simplest level of just displaying a solid color as its rearmost layer. But it has both a Backdrop and a Graphics property, and you use these to draw into a Canvas and into a window’s background in identical fashion. Also, a Canvas and a window receive some similar events. The treatment of window backgrounds at the end of Chapter 9 was rather sketchy; the expectation was that you ...

Get REALBasic: TDG, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.