Sams Teach Yourself Visual Basic 6 in 24 Hours
- Table of Contents
- Copyright
- About the Author
- Acknowledgments
- Introduction
- Who Should Read This Book
- What This Book Will Do for You
- Can This Book Really Teach Visual Basic in 24 Hours?
- What You Need
- Files on the Visual Basic Distribution CD-ROM
- Conventions Used in This Book
- Enough! Time Is Ticking!
- Part I: Introducing Visual Basic
- Hour 1. Visual Basic at Work
- Hour 2.Analyzing Visual Basic Programs
- Hour 3.Controls and Properties
- Hour 4.Examining Labels, Buttons, and Text Boxes
- Part II: Coding the Details
- Hour 5.Putting Code into Visual Basic
- Hour 6.Message and Input Boxes
- Hour 7.Making Decisions
- Hour 8.Visual Basic Looping
- Part III:Putting Code to Work
- Hour 9.Combining Code and Controls
- Hour 10.List Boxes and Data Lists
- Hour 11.Additional Controls
- Hour 12.Dialog Box Basics
- Part IV:Programming with Data
- Hour 13.Modular Programming
- Hour 14.Built-In Functions Save Time
- Hour 15.Visual Basic Database Basics
- Hour 16.Printing with Visual Basic
- Part V:Sprucing Up Programs
- Hour 17.Menus and Visual Basic
- Hour 18.The Graphic Image Controls
- Hour 19.Toolbars and More Graphics
- Hour 20.Writing Correct Applications
- Part VI:Advancing Visual Basic Applications
- Hour 21.Visual Basic and ActiveX
- Hour 22.Object Basics
- Hour 23.Distributing Your Applications
- Hour 24.Online Visual Basic
- Part VII:Appendixes
- Appendix A.Operator Precedence
- Appendix B.Answers
- Appendix C.Using the CD-ROM
Command Buttons
Command buttons appear in almost every window of every Windows application.
Command buttons determine when the user wants to do something such as exit the application or begin printing. In almost every case, you will perform these tasks to add a command button to an application:
- Locate and size the command button on the form.
- Change the command button's Name and Caption properties. (The Caption property holds the text that appears on the command button.)
- Add code to the command button's Click event procedure.
Although the command button control supports dozens of properties, you'll set only the Name and Caption properties in most cases. In addition, although command button controls support over a dozen events, you'll write code only for the Click event in most cases. After all, a command button resides on most forms so that the user can click the button to trigger some event that she wants to start.
Although you'll set the command button's Name and Caption properties most of the time, setting the Caption property often requires that you change the font to increase or decrease the text size and style on the caption. Of course, you might want to center the caption text or, perhaps, left-justify or right-justify the text, so you also might need to change the Alignment property. In reality, you'll also set the Left, Height, Top, and Width properties when you size and locate the command button because, as you learned in Hour 3, "Controls and Properties," these properties update automatically when you place and size controls.
As you can see, although you seem to set only a few properties for most controls, the other properties really do play important roles, and you'll almost always end up setting several properties to finalize your application. Table 4.1 lists some of the most common command button properties that you'll set.
An icon is a small graphical image that often appears on toolbar buttons. Icons are stored in a file with the .ico filename extension.
Table 4.1. Common command button properties.
| Property | Description |
| BackColor | Specifies the command button's background color. Click the BackColor's palette down arrow to see a list of colors, and click System to see a list of common Windows control colors. Before the command button displays the background color, you must change the Style property from 0-Standard to 1-Graphical. |
| Cancel | Determines whether the command button gets a Click event if the user presses Esc. |
| Caption | Holds the text that appears on the command button. |
| Default | Determines if the command button responds to an Enter keypress even if another control has the focus. |
| Enabled | Determines whether the command button is active. Often, you'll change the Enabled property with code at runtime when a command button is no longer needed and you want to gray out the command button. |
| Font | Produces a Font dialog box in which you can set the caption's font name, style, and size. |
| Height | Holds the height of the command button in twips. |
| Left | Holds the number of twips from the command button's left edge to the Form window's left edge. |
| MousePointer | Determines the shape of the mouse cursor when the user moves the mouse over the command button. |
| Picture | Holds the name of an icon graphic image that appears on the command button as long as the Style property is set to 1-Graphical. |
| Style | Determines whether the command button appears as a standard Windows command button (if set to 0-Standard) or a command button with a color and possible picture (if set to 1-Graphical). |
| TabIndex | Specifies the order of the command button in the focus order. |
| TabStop | Determines whether the command button can receive the focus. |
| ToolTipText | Holds the text that appears as a ToolTip at runtime. |
| Top | Holds the number of twips from the command button's top edge to the Form window's top edge. |
| Visible | Determines whether the command button appears or is hidden from the user. (Invisible controls cannot receive the focus until the running code changes the Visible property to True.) |
| Width | Holds the width of the command button in twips. |
Labels | Next Section

Account Sign In
View your cart