Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 3 - How to Code and Test a Windows Forms Appli...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

How to Code and Test a Windows Forms Application
By: Murach Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-07-08

    Table of Contents:
  • How to Code and Test a Windows Forms Application
  • How to refer to properties, methods, and events
  • How an application responds to events
  • How to add code to a form

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    How to Code and Test a Windows Forms Application - How an application responds to events


    (Page 3 of 4 )

    Windows Forms applications are event-driven. That means they work by responding to the events that occur on objects. To respond to an event, you code a procedure known as an event handler. In figure 3-3, you can see the event handler for the event that occurs when the user clicks the Exit button on the Invoice Total form. In this case, this event handler contains a single statement that uses the Close method to close the form.

    This figure also lists some common events for controls and forms. One control event you’ll respond to frequently is the Click event. This event occurs when the user clicks an object with the mouse. Similarly, the DoubleClick event occurs when the user double-clicks an object.

    Although the Click and DoubleClick events are started by user actions, that’s not always the case. For instance, the Enter and Leave events typically occur when the user moves the focus to or from a control, but they can also occur when code moves the focus to or from a control. Similarly, the Load event of a form occurs when a form is loaded into memory. For the first form of an application, this typically happens when the user starts the application. And the Closed event occurs when a form is closed. For the Invoice Total form in this figure, this happens when the user selects the Exit button or the Close button in the upper right corner of the form.

    In addition to the events shown here, most objects have many more events that the application can respond to. For example, events occur when the user positions the mouse over an object or when the user presses or releases a key. However, you don’t typically respond to those events.

    Event: The user clicks the Exit button

    Response: The procedure for the Click event of the Exit button is executed

      Private Sub btnExit_Click(ByVal sender As System.Object,
              ByVal e As System.EventArgs) Handles btnExit.Click
          Me.Close()
      End Sub

    Common control events  

     

    Event

    Occurs when…

    Click

    …the user clicks the control.

    DoubleClick

    …the user double-clicks the control.

    Enter

    …the focus is moved to the control.

    Leave

    …the focus is moved from the control.

     

     

    Common form events  

     

    Event

    Occurs when…

    Load

    …the form is loaded into memory.

    Closing

    …the form is closing.

    Closed

    …the form is closed.

     

    Concepts

    1. Windows Forms applications work by responding to events that occur on objects.
    2. To indicate how an application should respond to an event, you code an event handler, which is a Visual Basic procedure that handles the event. 
       
    3. An event can be an action that’s initiated by the user like the Click event, or it can be an action initiated by program code like the Closed event.

    Figure 3-3.   How an application responds to events

    More Visual Basic.NET Articles
    More By Murach Publishing


     

    Buy this book now. This article is excerpted from chapter three of Murach's Visual Basic 2008, written by Anne Boehm (Murach, 2008; ISBN: 1890774456). Check it out today at your favorite bookstore. Buy this book now.

    VISUAL BASIC.NET ARTICLES

    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek