1 / 21

Visual Basic .NET BASICS

Visual Basic .NET BASICS. Lesson 3 Events and Code. 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. Objectives (continued). Set picture properties. Set properties from code.

stevenpaul
Download Presentation

Visual Basic .NET BASICS

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. Visual Basic .NET BASICS Lesson 3 Events and Code

  2. 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. Objectives (continued) • Set picture properties. • Set properties from code. • Set the cancel and Default command button properties. • Create a stand-alone Windows program.

  4. Events • In an event-driven system, the computer is constantly waiting for the user to take some action with the mouse, keyboard, or other device. • That action triggers an event, and the software in the computer attempts to find something to do with that action.

  5. Events (continued) • When you create an object, such as a command button, it is up to you to write the code that will handle the events. • The code that you write to handle a specific event is called an event procedure.

  6. Accessing the Code Window • To add code to a command button, open the form that contains the command button and double-click the command button. The Code window will appear.

  7. Adding Code to a Command Button • To add code to the Code window, simply enter the code from the key-board much like you would use a word processor. • You can insert and delete text and use cut, copy, and paste. • IntelliSense will anticipate what you are about to key and complete your statement for you. • Visual Basic .NET is not case sensitive.

  8. Adding a Picture to a Form • A PictureBox control provides a framework for displaying a picture on a form.

  9. Setting Image Properties • Image controls have an extensive set of properties that can be changed.

  10. The Name Property • The name property names the PictureBox control.

  11. The SizeMode Property • The SizeMode property allows you to specify what should happen when the picture and the space available do not match.

  12. The Visible Property • The Visible property gives you control over when a picture is visible to the user.

  13. Setting Properties from Code • The SizeMode property allows you to specify what should happen when the picture and the space available do not match.

  14. The SizeMode Property • Visual Basic .NET allows you to change a property by specifying the name of the control, the property, and the value that you want to give the property. • 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 the object to set its own property by sending it a message.

  15. Adding Access Keys to Command Buttons • The Access Key is declared in the text property in Visual Basic .NET programs. • An access key allows a user to activate a command without using a mouse.

  16. Setting the AcceptButton and CancelButton Form Properties • The AcceptButton property names the command button to be used when the user presses the Enter key. • The CancelButton property holds the name of the command button on the form that will be activated when the user presses the Esc key.

  17. 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.

  18. Summary (continued) • The code you write in Visual Basic. NET 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 Basic. NET has IntelliSense features to help format your program code. • The End statement ends a program.

  19. Summary (continued) • The PictureBox tool allows you to add a Picture Box control to a form. • Using the Name property set to StretchImage causes a picture to resize to fit the dimensions of the PictureBox control. The SizeMode property set to AutoSize causes a PictureBox control to resize to fit the picture loaded into it. • The Visible property controls whether an object is showing or hidden.

  20. Summary (continued) • Setting properties from code is one of the most common uses for Visual Basic. NET code. Setting properties from code allows you to change properties while a program runs. • To change an object’s properties from code, you send a message to the object. The object uses a method to change the property.

  21. Summary (continued) • A command button with an ampersand (&) in front of a letter in the Text property causes that letter to become an access key. 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.

More Related