Presentation is loading. Please wait.

Presentation is loading. Please wait.

Microsoft Visual Basic 2005 BASICS Lesson 3 Events and Code.

Similar presentations


Presentation on theme: "Microsoft Visual Basic 2005 BASICS Lesson 3 Events and Code."— Presentation transcript:

1 Microsoft Visual Basic 2005 BASICS Lesson 3 Events and Code

2 Microsoft Visual Basic 2005 BASICS2 Objectives Describe events and how events are key to Windows programs. Access the Code window. Add code to a command button. Add a picture to a form.

3 Microsoft Visual Basic 2005 BASICS3 Objectives (cont.) Set picture properties. Use code to set properties. Set the Cancel and Default command button properties. Create a stand-alone Windows program.

4 Microsoft Visual Basic 2005 BASICS4 Events Event-driven system  Computer is constantly waiting for the user to take some action With the mouse, keyboard, or other device Action triggers an event  Software in the computer attempts to find something to do with that action

5 Microsoft Visual Basic 2005 BASICS5 Events (cont.) When you create an object  It is up to you to write the code that will handle the events. Event procedure  Code that handles a specific event

6 Microsoft Visual Basic 2005 BASICS6 Accessing the Code Window Add code to a command button  Open the form that contains the command button.  Double-click the command button. The Code window will appear. Subroutine  Section of code to perform a specific task

7 Microsoft Visual Basic 2005 BASICS7 Accessing the Code Window (cont.)

8 Microsoft Visual Basic 2005 BASICS8 Adding Code to a Command Button Add code to the Code window  Simply enter the code from the keyboard. You can insert and delete text and use cut, copy, and paste. IntelliSense technology  Anticipates what you are about to key Completes your statement for you Visual Basic is not case sensitive.

9 Microsoft Visual Basic 2005 BASICS9 Adding Code to a Command Button (cont.)

10 Microsoft Visual Basic 2005 BASICS10 Adding a Picture to a Form PictureBox control  Provides a framework for displaying a picture on a form

11 Microsoft Visual Basic 2005 BASICS11 Adding a Picture to a Form (cont.)

12 Microsoft Visual Basic 2005 BASICS12 Adding a Picture to a Form (cont.)

13 Microsoft Visual Basic 2005 BASICS13 Adding a Picture to a Form (cont.)

14 Microsoft Visual Basic 2005 BASICS14 Adding a Picture to a Form (cont.)

15 Microsoft Visual Basic 2005 BASICS15 Setting Image Properties Image controls  Have an extensive set of properties that can be changed

16 Microsoft Visual Basic 2005 BASICS16 The Name Property Name property  Names the PictureBox control The pic prefix is often used when naming PictureBox controls.

17 Microsoft Visual Basic 2005 BASICS17 The SizeMode Property SizeMode property  Allows you to specify what to do when picture and space available do not match Values  Normal  Center  StretchImage  AutoSize

18 Microsoft Visual Basic 2005 BASICS18 The SizeMode Property (cont.)

19 Microsoft Visual Basic 2005 BASICS19 The SizeMode Property (cont.)

20 Microsoft Visual Basic 2005 BASICS20 The Visible Property Visible property  Gives you control over when a picture is visible to the user

21 Microsoft Visual Basic 2005 BASICS21 Use Code to Set Properties Change a property by specifying  Name of the control  Property  Value

22 Microsoft Visual Basic 2005 BASICS22 Use Code to Set Properties (cont.) The item to the right of the dot is called a method. In object-oriented programming  You do not actually set the property.  You ask an object to set its own property by sending it a message.

23 Microsoft Visual Basic 2005 BASICS23 Use Code to Set Properties (cont.)

24 Microsoft Visual Basic 2005 BASICS24 Use Code to Set Properties (cont.)

25 Microsoft Visual Basic 2005 BASICS25 Adding Access Keys to Command Buttons Access key  Declared in the Text property in Visual Basic programs  Allows a user to activate a command without using a mouse

26 Microsoft Visual Basic 2005 BASICS26 Setting the AcceptButton and CancelButton Form Properties AcceptButton property  Names the command button to be used when the user presses the Enter key CancelButton property  Names the command button to be used when the user presses the Esc key

27 Microsoft Visual Basic 2005 BASICS27 Summary Windows is an event-driven environment. In an event-driven system, the user triggers events that control the work. To control what happens when an event occurs, you must write event procedures for each event that you want to handle. To access the Code window, double-click an object, such as a command button.

28 Microsoft Visual Basic 2005 BASICS28 Summary (cont.) Visual Basic code is written in sections called subroutines. Adding code is much like working in a word processor. The basic text-editing features are available. In addition, Visual Studio 2005 has IntelliSense features to help format your program code.

29 Microsoft Visual Basic 2005 BASICS29 Summary (cont.) The End statement ends a program. The PictureBox tool allows you to add a PictureBox control to a form. Using the (Name) property, you can give a PictureBox control a name. That name will be used when you refer to the control in code.

30 Microsoft Visual Basic 2005 BASICS30 Summary (cont.) Setting the SizeMode property to StretchImage causes a picture to resize to fit the dimensions of the PictureBox control. Setting the SizeMode property to AutoSize causes a PictureBox control to resize to fit the picture loaded into it. The Visible property controls whether an object is shown or hidden.

31 Microsoft Visual Basic 2005 BASICS31 Summary (cont.) Setting properties in code is one of the most common uses for Visual Basic code. Setting properties in code allows you to change properties while a program runs. A command button with an ampersand (&) in front of a letter in the Text property causes that letter to become an access key.

32 Microsoft Visual Basic 2005 BASICS32 Summary (cont.) The command button named in the form’s AcceptButton property will be activated when the user presses the Enter key. The command button named in the form’s CancelButton property will be activated when the user presses the Esc key.


Download ppt "Microsoft Visual Basic 2005 BASICS Lesson 3 Events and Code."

Similar presentations


Ads by Google