+ All Categories
Home > Documents > Visual Basic.NET BASICS Lesson 3 Events and Code.

Visual Basic.NET BASICS Lesson 3 Events and Code.

Date post: 03-Jan-2016
Category:
Upload: bridget-cannon
View: 216 times
Download: 1 times
Share this document with a friend
21
Visual Basic .NET BASICS Lesson 3 Events and Code
Transcript
Page 1: Visual Basic.NET BASICS Lesson 3 Events and Code.

Visual Basic .NET BASICS

Lesson 3

Events and Code

Page 2: 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.

Page 3: Visual Basic.NET BASICS Lesson 3 Events and Code.

3

Objectives (continued)

Set picture properties. Set properties from code. Set the cancel and Default command

button properties. Create a stand-alone Windows

program.

Page 4: Visual Basic.NET BASICS Lesson 3 Events and Code.

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.

Page 5: Visual Basic.NET BASICS Lesson 3 Events and Code.

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.

Page 6: Visual Basic.NET BASICS Lesson 3 Events and Code.

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.

Page 7: Visual Basic.NET BASICS Lesson 3 Events and Code.

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.

Page 8: Visual Basic.NET BASICS Lesson 3 Events and Code.

8

Adding a Picture to a Form

A PictureBox control provides a framework for displaying a picture on a form.

Page 9: Visual Basic.NET BASICS Lesson 3 Events and Code.

9

Setting Image Properties

Image controls have an extensive set of properties that can be changed.

Page 10: Visual Basic.NET BASICS Lesson 3 Events and Code.

10

The Name Property

The name property names the PictureBox control.

Page 11: Visual Basic.NET BASICS Lesson 3 Events and Code.

11

The SizeMode Property

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

Page 12: Visual Basic.NET BASICS Lesson 3 Events and Code.

12

The Visible Property

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

Page 13: Visual Basic.NET BASICS Lesson 3 Events and Code.

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.

Page 14: Visual Basic.NET BASICS Lesson 3 Events and Code.

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.

Page 15: Visual Basic.NET BASICS Lesson 3 Events and Code.

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.

Page 16: Visual Basic.NET BASICS Lesson 3 Events and Code.

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.

Page 17: Visual Basic.NET BASICS Lesson 3 Events and Code.

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.

Page 18: Visual Basic.NET BASICS Lesson 3 Events and Code.

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.

Page 19: Visual Basic.NET BASICS Lesson 3 Events and Code.

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.

Page 20: Visual Basic.NET BASICS Lesson 3 Events and Code.

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.

Page 21: Visual Basic.NET BASICS Lesson 3 Events and Code.

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.


Recommended