Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 4 - 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 to add code to a form


    (Page 4 of 4 )

    Now that you understand some of the concepts behind object-oriented coding, you’re ready to learn how to add code to a form. Because you’ll learn the essentials of the Visual Basic language in the chapters that follow, though, I won’t focus on the coding details right now. Instead, I’ll focus on the concepts and mechanics of adding the code to a form.

    How to create an event handler for the default event of a form or control

    Although you can create an event handler for any event of any object, you’re most likely to create event handlers for the default event of a form or control. So that’s what you’ll learn to do in this chapter. Then, in chapter 6, you’ll learn how to create event handlers for other events.

    To create an event handler for the default event of a form or control, you double-click the object in the Form Designer. When you do that, Visual Studio opens the Code Editor, generates a procedure declaration for the default event of the object, and places the insertion point between the Sub and End Sub statements that it has generated. Then, you can enter the Visual Basic statements for the procedure between the Sub and End Sub statements.

    To illustrate, figure 3-4 shows the Sub and End Sub statements that were generated when I double-clicked the Calculate button on the Invoice Total form. In the Sub statement, Visual Studio generated a procedure name that consists of the name of the object that the event occurred on (btnCalculate), an underscore, and the name of the event (Click).

    This procedure name is followed by two arguments in parentheses that you’ll learn more about later. And the arguments are followed by a Handles clause that says that the procedure is designed to handle the Click event of the button named btnCalculate. It is this clause, not the procedure name, that determines what event the procedure handles.

    For now, you should avoid modifying the procedure declaration that’s generated for you when you create an event handler. In chapter 6, though, you’ll learn how to modify the declaration so a single procedure can provide for more than one event.

    The procedure that handles the Click event of the Calculate button

    How to handle the Click event of a button

    1. In the Form Designer, double-click the control. This opens the Code Editor, generates the declaration for the procedure that handles the event, and places the cursor within this declaration.
    2. Type the Visual Basic code between the Sub statement and the End Sub statement. 
       
    3. When you finish entering the code, you can return to the Form Designer by clicking the View Designer button in the Solution Explorer window.

    How to handle the Load event for a form

    • Follow the procedure shown above, but double-click the form itself.

    Description

    1. The procedure declaration for the event handler that’s generated when you double-click on an object in the Form Designer includes a procedure name that consists of the object name, an underscore, and the event name.
    2. The Handles clause in the procedure declaration determines what event the procedure handles using the object name, dot, event name syntax. 
       
    3. In chapter 6, you’ll learn how to handle events other than the default event.

    Figure 3-4.   How to create an event handler for the default event of a form or control

     

  • Please check back tomorrow for the continuation of this article.

     

     

  • DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    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 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek