Ppt lesson 03


Published on

  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Ppt lesson 03

  1. 1. Microsoft Visual Basic 2005 BASICS Lesson 3 Events and Code
  2. 2. Objectives <ul><li>Describe events and how events are key to Windows programs. </li></ul><ul><li>Access the Code window. </li></ul><ul><li>Add code to a command button. </li></ul><ul><li>Add a picture to a form. </li></ul>
  3. 3. Objectives (cont.) <ul><li>Set picture properties. </li></ul><ul><li>Use code to set properties. </li></ul><ul><li>Set the Cancel and Default command button properties. </li></ul><ul><li>Create a stand-alone Windows program. </li></ul>
  4. 4. Events <ul><li>Event-driven system </li></ul><ul><ul><li>Computer is constantly waiting for the user to take some action </li></ul></ul><ul><ul><ul><li>With the mouse, keyboard, or other device </li></ul></ul></ul><ul><li>Action triggers an event </li></ul><ul><ul><li>Software in the computer attempts to find something to do with that action </li></ul></ul>
  5. 5. Events (cont.) <ul><li>When you create an object </li></ul><ul><ul><li>It is up to you to write the code that will handle the events. </li></ul></ul><ul><li>Event procedure </li></ul><ul><ul><li>Code that handles a specific event </li></ul></ul>
  6. 6. Accessing the Code Window <ul><li>Add code to a command button </li></ul><ul><ul><li>Open the form that contains the command button. </li></ul></ul><ul><ul><li>Double-click the command button. </li></ul></ul><ul><ul><ul><li>The Code window will appear. </li></ul></ul></ul><ul><li>Subroutine </li></ul><ul><ul><li>Section of code to perform a specific task </li></ul></ul>
  7. 7. Accessing the Code Window (cont.)
  8. 8. Adding Code to a Command Button <ul><li>Add code to the Code window </li></ul><ul><ul><li>Simply enter the code from the keyboard. </li></ul></ul><ul><li>You can insert and delete text and use cut, copy, and paste. </li></ul><ul><li>IntelliSense technology </li></ul><ul><ul><li>Anticipates what you are about to key </li></ul></ul><ul><ul><ul><li>Completes your statement for you </li></ul></ul></ul><ul><li>Visual Basic is not case sensitive. </li></ul>
  9. 9. Adding Code to a Command Button (cont.)
  10. 10. Adding a Picture to a Form <ul><li>PictureBox control </li></ul><ul><ul><li>Provides a framework for displaying a picture on a form </li></ul></ul>
  11. 11. Adding a Picture to a Form (cont.)
  12. 12. Adding a Picture to a Form (cont.)
  13. 13. Adding a Picture to a Form (cont.)
  14. 14. Adding a Picture to a Form (cont.)
  15. 15. Setting Image Properties <ul><li>Image controls </li></ul><ul><ul><li>Have an extensive set of properties that can be changed </li></ul></ul>
  16. 16. The Name Property <ul><li>Name property </li></ul><ul><ul><li>Names the PictureBox control </li></ul></ul><ul><li>The pic prefix is often used when naming PictureBox controls. </li></ul>
  17. 17. The SizeMode Property <ul><li>SizeMode property </li></ul><ul><ul><li>Allows you to specify what to do when picture and space available do not match </li></ul></ul><ul><li>Values </li></ul><ul><ul><li>Normal </li></ul></ul><ul><ul><li>Center </li></ul></ul><ul><ul><li>StretchImage </li></ul></ul><ul><ul><li>AutoSize </li></ul></ul>
  18. 18. The SizeMode Property (cont.)
  19. 19. The SizeMode Property (cont.)
  20. 20. The Visible Property <ul><li>Visible property </li></ul><ul><ul><li>Gives you control over when a picture is visible to the user </li></ul></ul>
  21. 21. Use Code to Set Properties <ul><li>Change a property by specifying </li></ul><ul><ul><li>Name of the control </li></ul></ul><ul><ul><li>Property </li></ul></ul><ul><ul><li>Value </li></ul></ul>
  22. 22. Use Code to Set Properties (cont.) <ul><li>The item to the right of the dot is called a method. </li></ul><ul><li>In object-oriented programming </li></ul><ul><ul><li>You do not actually set the property. </li></ul></ul><ul><ul><li>You ask an object to set its own property by sending it a message. </li></ul></ul>
  23. 23. Use Code to Set Properties (cont.)
  24. 24. Use Code to Set Properties (cont.)
  25. 25. Adding Access Keys to Command Buttons <ul><li>Access key </li></ul><ul><ul><li>Declared in the Text property in Visual Basic programs </li></ul></ul><ul><ul><li>Allows a user to activate a command without using a mouse </li></ul></ul>
  26. 26. Setting the AcceptButton and CancelButton Form Properties <ul><li>AcceptButton property </li></ul><ul><ul><li>Names the command button to be used when the user presses the Enter key </li></ul></ul><ul><li>CancelButton property </li></ul><ul><ul><li>Names the command button to be used when the user presses the Esc key </li></ul></ul>
  27. 27. Summary <ul><li>Windows is an event-driven environment. In an event-driven system, the user triggers events that control the work. </li></ul><ul><li>To control what happens when an event occurs, you must write event procedures for each event that you want to handle. </li></ul><ul><li>To access the Code window, double-click an object, such as a command button. </li></ul>
  28. 28. Summary (cont.) <ul><li>Visual Basic code is written in sections called subroutines. </li></ul><ul><li>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. </li></ul>
  29. 29. Summary (cont.) <ul><li>The End statement ends a program. </li></ul><ul><li>The PictureBox tool allows you to add a PictureBox control to a form. </li></ul><ul><li>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. </li></ul>
  30. 30. Summary (cont.) <ul><li>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. </li></ul><ul><li>The Visible property controls whether an object is shown or hidden. </li></ul>
  31. 31. Summary (cont.) <ul><li>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. </li></ul><ul><li>A command button with an ampersand (&) in front of a letter in the Text property causes that letter to become an access key. </li></ul>
  32. 32. Summary (cont.) <ul><li>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. </li></ul>