Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 2 - 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 refer to properties, methods, and events


    (Page 2 of 4 )

    As you enter the code for a form in the Code Editor window, you often need to refer to the properties, methods, and events of its objects. To do that, you type the name of the object, a period (also known as a dot operator, or dot), and the name of the member. This is summarized in figure 3-2.

    In some cases, you will refer to the properties and methods of a class instead of an object that’s instantiated from the class. You’ll see examples of that in later chapters. For now, you just need to realize that you refer to these properties and methods using the same general syntax that you use to refer to the properties and methods of an object. You enter the class name, a dot, and the property or method name.

    To make it easier for you to refer to the members of an object or class, Visual Studio’s IntelliSense feature displays a list of the members that are available for that class or object after you type a class or object name and a period. Then, you can highlight the entry you want by clicking on it, typing one or more letters of its name, or using the arrow keys to scroll through the list. In most cases, you can then complete the entry by pressing the Tab or Enter key.

    To give you an idea of how properties, methods, and events are used in code, this figure shows examples of each. In the first example for properties, code is used to set the value that’s displayed for a text box to 10. In the second example, code is used to set the ReadOnly property of a text box to True. Although you can also use the Properties window to set these values, that just sets the properties at the start of the application. By using code, you can change the properties as an application is running.

    In the first example for methods, the Select method of a text box is used to move the focus to that text box. In the second example, the Close method of a form is used to close the active form. In this example, the Me keyword is used instead of the name of the form. Here, Me refers to the current instance of the active form. Note also that the names of the methods are followed by parentheses. If a method requires parentheses like these, they’re added automatically when you press the Enter key after entering the method name.

    As you progress through this book, you’ll learn how to use the methods for many types of objects, and you’ll learn how to supply arguments within the parentheses of a method. For now, though, just try to understand that you can call a method from a class or an object.

    Although you’ll frequently refer to properties and methods as you code an application, you’ll rarely need to refer to an event. That’s because Visual Studio automatically generates the code for working with events, as you’ll see later in this chapter. To help you understand the code that Visual Studio generates, however, the last example in this figure shows how you refer to an event. In this case, the code refers to the Click event of a button named btnExit.

    A member list that’s displayed in the Code Editor window

    The syntax for referring to a member of a class or object

      ClassName.MemberName
      objectName.MemberName

    Statements that refer to properties

     

    txtTotal.Text = 10 Assigns the value 10 to the Text property of the text box named txtTotal.  
    txtTotal.ReadOnly = True Assigns the True value to the ReadOnly property of the text box named txtTotal so the user can’t change its contents.
      

     

    Statements that refer to methods  

     

    txtMonthlyInvestment.Select()

    Uses the Select method to move the focus to the text box named txtMonthlyInvestment.

    Me.Close()

    Uses the Close method to close the form that contains the statement. In this example, Me is a keyword that is used to refer to the current instance of the form class.

     

     

    Code that refers to an event  

     

    btnExit.Click

    Refers to the Click event of a button named btnExit.

     

     

    How to enter member names when working in the Code Editor

    1. To display a list of the available members for a class or an object, type the class or object name followed by a period (called a dot operator, or just dot). Then, type one or more letters of the member name, and Visual Studio will filter the list so that only the members that start with those letters are displayed. You can also scroll through the list to select the member you want.
    2. Once you’ve selected a member, you can press the Tab key to insert it into your code, or you can press the Enter key to insert the member and start a new line of code. 
       
    3. By default, all the available members are displayed in the list. To display just the common members, click the Common tab at the bottom of the list. 
       
    4. If a member list isn’t displayed, select the Tools->Options command to display the Options dialog box. Then, expand the Text Editor group, select the Basic group, and check the Auto List Members and Parameter Information boxes.

    Figure 3-2.  How to refer to properties, methods, and 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 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek