3 2 vb net events
This presentation is the property of its rightful owner.
Sponsored Links
1 / 18

3.2 VB.NET Events PowerPoint PPT Presentation


  • 73 Views
  • Uploaded on
  • Presentation posted in: General

3.2 VB.NET Events. An Event Procedure Properties and Event Procedures of the Form Tab Order of Controls Exercises. An Event Procedure. An event is an action, such as the user clicking on a button Usually, nothing happens until the user does something and generates an event.

Download Presentation

3.2 VB.NET Events

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


3 2 vb net events

3.2 VB.NET Events

  • An Event Procedure

  • Properties and Event Procedures of the Form

  • Tab Order of Controls

  • Exercises


An event procedure

An Event Procedure

  • An event is an action, such as the user clicking on a button

  • Usually, nothing happens until the user does something and generates an event

Demo – Sales Order app with no code


The three steps in creating a vb net program

The three steps in creating a VB.NET program:

  • Create the interface; that is, generate, position, and size the objects.

  • Set properties; that is, configure the appearance of the objects.

  • Write the code that executes when events occur.


Changing properties

Changing Properties

  • Properties can be changed in code with the following:

    controlName.property = setting

  • This is an assignment statement

    txtBox.ForeColor = Color.Red

Note: Right side is always assigned to left side

Demo: blank sol’n


Object properties

Object Properties

  • Some are values, some are string, some are boolean (true or false)

  • Strings always go in quotes!txtBox.text = “Enter a phrase”

  • Boolean and values do not have quotes


Control name prefixes

Control Name Prefixes

Note: Can be named anything but this is a convention

Ensure your naming is intuitive!


Most common errors

Most Common Errors

  • Misspelling the name of a control in code

  • VB editor will help you!

  • Renaming controls does not update in the body of an event procedure


Event procedures

Event Procedures

Private SubobjectName_event(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles objectName.event

Shown in the book as:

Private SubobjectName_event(…) HandlesobjectName.event

Each object has default event procedure – double click it

you are unsure – try a label, textbox, button and listbox


Structure of an event procedure

Structure of an Event Procedure

Private Sub objectName_event(...)

Handles objectName.event

statements

End Sub

Sometimes there are multiple actions that can

trigger an event – e.g. Textbox.enter event


Program region

Program Region


Intellisense

IntelliSense

Automatically pops up to give the programmer help.

Demo: wrong spelling for a control


Code for walkthrough

Code for Walkthrough

Private Sub txtFirst_TextChanged(...)

Handles txtFirst.TextChanged

txtFirst.ForeColor = Color.Blue

End Sub

Private Sub btnRed_Click(...)

Handles btnRed.Click

txtFirst.ForeColor = Color.Red

End Sub

Private Sub txtFirst_Leave(...)

Handles txtFirst.Leave

txtFirst.ForeColor = Color.Black

End Sub


Event demo

Event Demo

Private Sub txtBox_MouseHover ….

txtBox.BackColor = Color.AliceBlue

End Sub

Private Sub txtBox_MouseLeave ….

txtBox.BackColor = Color.White

End Sub


Running code

Running Code

  • From menu – Debug – Run

  • Or F5

  • Be careful – code is automatically saved when run


Assigning properties in code

Assigning properties in code

  • The following won't work:

    Form1.Text = "Demonstration"

  • The form is referred to by the keyword Me.

    Me.Text = "Demonstration"


The declaration statement of an event procedure

The Declaration Statement of an Event Procedure

  • A declaration statement for an event procedure:

    Private Sub btnOne_Click(...) Handles btnOne.Click

  • The name can be changed at will. For example

    Private Sub ButtonPushed(...) Handles btnOne.Click

  • Handling more than one event:

    Private Sub ButtonPushed(...) Handles btnOne.Click, btnTwo.Click


Tab order of controls

Tab Order of Controls

  • Determines which control gets the focus when you hit the Tab key

  • Order is initially established by the order controls are placed on the form

  • Controlled by tabindex property

  • Demo with Sales Order form


Exercises p 69 to 74

Exercises p. 69 to 74

Do #37 together & #38 aloneHomework - #46 – page 74

Solutions to odd numbers are in the back of text book – try some on your own!


  • Login