1 / 26

Basic Controls & Properties

Basic Controls & Properties. Chapter 2. Overview. VB-IDE Basic Controls Command Button Label Text Box Picture Box Program Editor Setting Properties with Code. The Visual Basic IDE. The Workspace & Toolbox. Selecting Tools.

betty
Download Presentation

Basic Controls & Properties

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Basic Controls & Properties Chapter 2

  2. Overview • VB-IDE • Basic Controls • Command Button • Label • Text Box • Picture Box • Program Editor • Setting Properties with Code

  3. The Visual Basic IDE

  4. The Workspace & Toolbox

  5. Selecting Tools • Using the toolbox and the Workspace Window you can build a form that has nearly any desired appearance • Double click on an icon in the toolbox to create a new instance of that type of object in your workspace • These objects are called controls • Using the mouse, a control can be resized or moved

  6. The Project Window • This window allows you to select and open one or more forms that are used in a given project.

  7. You may use this window to adjust the position of the form on the CRT screen. Clicking on the “X” will close this window and leave room for other things. The Form Layout Window

  8. The Properties Window • This window allows you to examine and modify the various properties of control objects in a program • Properties govern the appearance and behavior of a control object • They may be modified using the properties window, or by VB code

  9. The Command Control • The command control is one of the most important tools in the toolbox • Double clicking on the command button icon will install a command button on the working form Command Button

  10. Adding a Command Button • The command buttons are named, by default Command1, Command2, etc. • They may be moved or changed in size using the mouse

  11. Properties of Command Buttons • Each command button has several properties. govern the button’s appearance and behavior • The most important are the (name) and the caption • (name) is how a programmer can refer to the button in VB code • captionis the text a user will see displayed inside the button

  12. Highlighting a Property • When you highlight a property, its definition appears below the properties window

  13. Names and Captions • Clicking on the (name) property lets us name it “cmdstop”, (note the name starts with “cmd”) • Changing the caption to “Stop” gives the user an idea as to the button’s function

  14. Naming Convention • Good practice in Visual Basic suggests that we should name all objects in a program with names that indicate their function • These names are invariant during a program’s execution and are seen only by programmers • Command buttons names should begin with the prefix “cmd” • Names should begin with the prefix for the given object type, and should contain only letters and numbers • Captions are used to convey information to the user • They can change as the program runs • They may contain any letters, numbers, spaces, etc.

  15. Command Buttons & The Program Editor • Visual Basic (VB) supports a text editor (not a word processor) that permits the writing and modification of program code • The program editor is one of two sub-windows that appears in the Workspace • The other is the Forms window • Many of the commands used in the program editor are like those used in word processors, but there are differences

  16. Entering the Editor • The editor is normally entered by “double clicking” on an “Event Producing Object” in the workspace. • The result is a code window which opens with the “subroutine” describing that event as the focus.

  17. Entering Event Code • Double clicking on the “cmdStop” button itself, causes the Code window to open • The VB commands that define the button’s function go here • The “End” command terminates the VB program

  18. The Label Control • The label control is an object with 37 named Properties • You can adjust its size and positionwith the mouse • You can change its (name) its caption and visibility using the Properties window

  19. Label Control Properties

  20. Using Labels • The label control is usable only for output • It cannot accept input from the user • Its size, shape, color, visibility and the form of the information presented can be controlled • By editing its properties • By writing VB code to change its properties • Labels can be sized and moved using the mouse.

  21. A Program Using a Label

  22. When program execution begins, the system starts as in “A”, when the cmdby button is pressed the system goes to “B” Repeated pressing of the cmdby button bounces the system between the two states Using a Label

  23. Naming Convention • Labels should be given a (name) that begins with “lbl”. • The Caption property of a label may be anything that makes sense; one or more words or symbols. • Caption is displayed for the user • (name) is only accessible to the programmer • The Visible property may be either True or False • If false, the label is not displayed

  24. 3. The Text Box Control • Labels are designed to be used for output • Command buttons can accept input from the user, but only of a limited nature • The text box control allows the user input data

  25. Text Box Properties • The text property contains the string of text displayed by the text box • Unlike labels, by default this text can be edited by the user at runtime • The proper prefix for text box names is txt • Text boxes do not have Caption property!

  26. 4. The Picture Box • The Picture box control can be used to display a picture on the form • The proper prefix for picture box names is pct • Click on its Picture property • A command button with an ellipsis (…) will be displayed • By clicking on the button, a dialog box will appear to select the graphic file to display within the picture box control

More Related