
Beginning REALbasic - From Novice To Professional (2006)
.pdf
76 |
C H A P T E R 3 ■ C R E A T I N G A N A P P L I C A T I O N ’ S U S E R I N T E R F A C E |
USING PREBUILT POP-UP WINDOWS
At times, all your application needs to do is display a brief message for the user to read or collect a Yes/No type response to a simple question. Rather than creating, and then customizing, a new window to serve this purpose, you can, instead, use either of two REALbasic options for displaying pop-up styled dialog boxes. One of these options is the MsgBox function, which is best suited to displaying informational messages. The MsgBox function is also included in REALbasic to help facilitate the conversion of Visual Basic applications that use a similarly named Visual Basic function.
Your other option for creating pop-up styled dialog boxes is the MessageDialog class, which gives you more control over how text is displayed and how dialog buttons look. Information on how to work with the MsgBox function is provided in Chapter 8. Information and examples of how to use the MessageDialog class are also available in Chapter 8.
You learn from examples in upcoming chapters how to set up your application to call on and display other windows you may add.
Deleting Windows
As you work on your applications, you may find you no longer need a particular window anymore. In addition, as you are adding new windows to your applications, you may accidentally add an extra window when you did not mean to. In either of these circumstances, you can delete any unwanted windows either by selecting them in the Project Editor and pressing Delete or by clicking Edit Delete.
■Tip You can also delete a window from your application by right-clicking (control-clicking on Macintosh) on the window and selecting Delete from the contextual menu that appears.
Encrypting and Decrypting Windows
If you plan on sharing or selling the source code for your applications with other REALbasic programmers, you may want to consider encrypting one or more of the windows that make up your application. For example, if you developed a particular piece of code you consider proprietary, you may want to protect it from the view by other programmers, while still sharing the rest of the code that makes up the application.
You can achieve this by encrypting the window with which the code to be protected is associated. When you encrypt a window, you do so by supplying a password. Anyone who later attempts to open the window is prompted to supply the password, without which the window and its associated code will not be displayed.
To encrypt a window, you must first select it in the Project Editor, and then click Edit Encrypt. This opens the Encrypt Window dialog, as Figure 3-13 shows. You must supply the required password two times, and then click the Encrypt button.

C H A P T E R 3 ■ C R E A T I N G A N A P P L I C A T I O N ’ S U S E R I N T E R F A C E |
77 |
Figure 3-13. Encrypting a window to protect its contents from being viewed
■Tip You can also encrypt a window by right-clicking it (control-clicking on Macintosh) and selecting Encrypt from the contextual menu that appears.
Once encrypted, a window can only be viewed and modified by decrypting it. To do this, select the window, and then click Edit Decrypt. This opens the Decrypt Window, shown in Figure 3-14, where you are prompted to supply the window’s associated password.
Figure 3-14. You must supply a password to decrypt and view an encrypted window.
■Tip You can also decrypt an encrypted window by selecting it in the Project Editor and right-clicking it (control-clicking on Macintosh) and selecting Decrypt from the contextual menu that appears.
Working with Controls
Users interact with desktop applications by working with controls that you place on top of their windows. REALbasic makes controls available to you on the Controls pane, located on the Windows Editor.
In most cases, REALbasic controls are visible to the end user, who must interact with them to work with your application. However, some controls, such as the StaticText control, are “display only,” meaning that although the user sees them, no actual interaction occurs. Still other controls are completely invisible to the user. These controls are visible to you as icons residing on your windows within REALbasic’s IDE, but they will not be visible when your application runs. Adding these types of controls to your applications makes available specific functionality provided by the control. For example, the Timer control provides you with the capability to execute code on a schedule basis and the TCPSocket control provides you with the capability to create applications that can communicate over networks and the Internet.

78 |
C H A P T E R 3 ■ C R E A T I N G A N A P P L I C A T I O N ’ S U S E R I N T E R F A C E |
Adding Controls to Windows
As you already saw in previous examples, you can add controls to application windows by dragging-and-dropping them. You can also add controls by double-clicking them. When you do this, REALbasic adds a copy of the control to the window, leaving it up to you to change its location and size, as appropriate.
■Tip You can also add controls to your REALbasic applications by right-clicking the background of a window, and then selecting the Add option from the contextual menu that appears. REALbasic responds by displaying a list of objects you can add to the window.
You can also add a control to your application windows by clicking the control to select it, and then using the pointer to draw the area where you want the control placed. The advantage of using this technique is this: it not only places the control where you want it, but it also resizes the control to fit the area you drew.
■Tip If you need to add more than one instance of the same control to a window, such as when adding multiple CheckBox or RadioButton controls, you can add each type of control one time, and then duplicate each control as many times as necessary. You do this by selecting a control, and then selecting Edit Duplicate.
Finding Lost Controls
As you design your windows by adding and modifying controls, controls can sometimes disappear. This can happen if you place one control over the top of another. This can also happen if you add a control to a window, and then accidentally modify its Top and Left properties with a negative value, causing the control to be removed from view.
You can view a listing of all the controls that were added to a window by right-clicking the window where the control resides and clicking Select, followed by the control you are looking for. Once selected, you can modify the control’s properties as necessary to bring it back into view.
Modifying Control Properties
You can modify control properties in several ways. One is to programmatically modify them from within program code. Another is to physically move or resize the control within a window. A third option is to modify control properties displayed within the Properties pane after the control is selected.

C H A P T E R 3 ■ C R E A T I N G A N A P P L I C A T I O N ’ S U S E R I N T E R F A C E |
79 |
In addition to modifying the properties for one control at a time, as demonstrated in previous chapters, you can also select two or more controls and modify their properties at the same time. You can select more than one control by using the pointer to draw a selection area around them. You can also select more than one control by pressing Control, while clicking on multiple controls. When more than one control is selected, REALbasic responds by displaying properties common to all selected controls. When modifying a property in this manner, the result is a change to the same property for each selected control.
Deleting Controls
If you accidentally add more controls to a window than you need, you can easily remove them. To do so, open the window where the control resides and select the control. Next, click Edit Cut or Edit Delete to remove the control. By cutting the control instead of deleting it, you paste a copy of the control on the clipboard of the operating system (OS), enabling you to paste it into other windows.
■Tip You can also remove controls from a window by right-clicking the control (control-clicking on Macintosh) and selecting Cut or Delete from the contextual menu displayed.
A REALbasic Control Overview
REALbasic includes dozens of built-in controls, each of which is designed to provide a specific type of functionality to your REALbasic applications. In the following sections, you get an overview of each of these controls and their functionality. As you progress through the rest of the chapters in this book, you have the opportunity to see many of these controls in action.
The BevelButton Control
The BevelButton control, as Figure 3-15 shows, is similar to the PushButton control you already worked with in the first two chapters of this book. The only difference is that, with the BevelButton control, you can add both text and an image to the BevelButton control and specify their positioning within the control.
Figure 3-15. Examples of the BevelButton, as shown on Windows

80 |
C H A P T E R 3 ■ C R E A T I N G A N A P P L I C A T I O N ’ S U S E R I N T E R F A C E |
The Canvas Control
The Canvas control, seen in Figure 3-16, is used to display pictures or to draw a picture using REALbasic’s programming statements. The Canvas control can also be used as a foundation for building a custom control.
Figure 3-16. An example of the Canvas control, as shown on Windows
■Tip Another special type of control you might want to look into is the Container control, which provides you with the capability to group together other controls to create reuseable interface components. The creation of custom controls using the Canvas and Container controls is an advanced programming topic, and is out of the scope of this book. However, programmers with a strong Visual Basic background may want to explore these controls further in REALbasic’s Reference manual. Using these controls as a starting point, Visual Basic programmers can create custom controls to re-create any Visual Basic controls for which REALbasic does not provide an equivalent control.
The CheckBox Control
The CheckBox control, which Figure 3-17 shows, is used to provide users with choices that have two options or states. You can use check boxes to perform tasks, such as collecting user preferences or enabling and disabling specific application features.

C H A P T E R 3 ■ C R E A T I N G A N A P P L I C A T I O N ’ S U S E R I N T E R F A C E |
81 |
Figure 3-17. An example of Checkbox controls, as shown on Linux
The ComboBox Control
The ComboBox control, as you see in Figure 3-18, provides features found in both the EditField and PopupMenu controls. You can use it to enable users either to type input or select an item from a list of items.
Figure 3-18. An example of the ComboBox control, as shown on Linux
Once a ComboBox is selected, users can use the up and down arrows to locate an item, and then press Enter or Return to select it, or press Escape to close the pop-up list without making a selection.
The ContextualMenu Control
The ContextualMenu control, as shown in Figure 3-19, is used to display a pop-up list of choices for any control that supports it. Once created, one ContextualMenu can be associated with any number of controls and is accessed by right-clicking (control-clicking on Macintosh) on an associated control. More information on how to work with this control is in Chapter 4.
Figure 3-19. An example of the ContextualMenu control, as shown on Linux
The DatabaseQuery Control
When added to a window, the DatabaseQuery control provides your application with the capability to submit a SQL query to a database when the window to which it was added loads. Note, while this control provides the capability to query a database, it is invisible to the user. For more information on how to work with the DatabaseQuery, read Chapter 10.

82 |
C H A P T E R 3 ■ C R E A T I N G A N A P P L I C A T I O N ’ S U S E R I N T E R F A C E |
The DataControl Control
The DataControl control, seen in Figure 3-20, provides your application with the capability to create a database front end, enabling users to navigate the database by moving forward or backward, or by jumping to the database’s first or last records.
Figure 3-20. An example of the DataControl control, as shown on Windows
Typically, you use this control to control the display of database data in EditFields and other controls. For more information on how to work with the DataControl, see Chapter 10.
The DisclosureTriangle Control
The DisclosureTriangle control, shown in Figure 3-21, is used to build an interface that can display a hierarchical listing of files and folders. REALbasic enables you to control the direction in which the DisclosureTriangle points (left or right), as well as whether it is in a disclosed (down) or undisclosed (up) state.
Figure 3-21. An example of a DisclosureTriangle control, as shown on Mac OS X
The EditField Control
The EditField control, as seen in Figure 3-22, is used to enable the user to enter and to display text. The EditField supports single line and multiline text input. With single-line input, the EditField control provides the capability to display or collect small amount of user input.
With multiline input, the EditField provides the capability to accept and display text using features commonly associated with Word processors. These multiline EditField control features include the capability to display text in
•Different fonts
•Different colors
•Different sizes
The EditField control’s multiline features also include the capability to display scrollbars and to format paragraphs.

C H A P T E R 3 ■ C R E A T I N G A N A P P L I C A T I O N ’ S U S E R I N T E R F A C E |
83 |
Figure 3-22. Two examples of the EditField control, as shown on Linux
The ExcelApplication Control
The ExcelApplication control is one of three REALbasic controls that provide you with the capability to develop applications that incorporate Microsoft Office functionality into your applications, provided Microsoft Office is installed on the computer where the applications executes. This control is used to integrate Microsoft Excel functionality into REALbasic applications. This control is invisible to the user.
The ExcelApplication control works with Microsoft Office 2000 and 2003 on computers running Windows and Office 98, and Office 2001 on Macintosh. Also, Microsoft Office X is supported on Mac OS X. Microsoft Office Applications do not run on Linux, so this control is not supported on that OS.
■Note To effectively use this control, you must have some familiarity with Microsoft VBA, which you can find published in numerous books, including Definitive Guide to Excel VBA, Second Edition (ISBN: 1590591038), published by Apress.
The GroupBox Control
The GroupBox control, which you can see in Figure 3-23, is typically used to group together related controls on a window. The GroupBox control is particularly useful for grouping RadioButton controls, which allow different groups of RadioButton controls to operate independently of each other.

84 |
C H A P T E R 3 ■ C R E A T I N G A N A P P L I C A T I O N ’ S U S E R I N T E R F A C E |
Figure 3-23. Examples of the GroupBox control, as shown on Linux
The HTMLViewer Control
The HTMLViewer control, seen in Figure 3-24, provides your applications with the capability to function like a web browser. The HTMLViewer control can display any URL or even render HTML code that is passed to it.
Figure 3-24. An example of the HTMLViewer control, as shown on Windows
The ImageWell Control
Like the Canvas control, the ImageWell control, as shown in Figure 3-25, provides you with the capability to display BMP and PNG images on Windows and Linux, and PICT images on Macintosh. However, unlike the Canvas control, which can be used as the basis for building custom controls, the ImageWell control is limited to only displaying graphic images.

C H A P T E R 3 ■ C R E A T I N G A N A P P L I C A T I O N ’ S U S E R I N T E R F A C E |
85 |
Figure 3-25. An example of the ImageWell control, as shown on Windows
The Line Control
The Line control, which you see in Figure 3-26, provides you with the capability to draw a line on an application window. The line can be any length and thickness. The default width of a line is 1 pixel, drawn horizontally in black.
Figure 3-26. An example of the Line control, as shown on Linux
■Note A pixel is the smallest addressable area on a picture or screen that you can write to.
The ListBox Control
The ListBox control, shown in Figure 3-27, provides the capability to display a list of choices. This list can be made up of one or more columns and can even display headings. Once selected, the user can navigate the contents of the ListBox control using the up and down keys, and selecting a choice by pressing Enter or Return.