3 2 vb net events n.
Skip this Video
Download Presentation
3.2 VB.NET Events

Loading in 2 Seconds...

play fullscreen
1 / 18

3.2 VB.NET Events - PowerPoint PPT Presentation

  • Uploaded on

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.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about '3.2 VB.NET Events' - cole

Download Now 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


End Sub

Sometimes there are multiple actions that can

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


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!