Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 4 - Inheritance and Windows Forms
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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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

Inheritance and Windows Forms
By: Mohammed Qattan
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 25
    2004-01-26

    Table of Contents:
  • Inheritance and Windows Forms
  • Exploring Forms
  • Validating Inputs
  • Carrying Out the Scenario
  • Explanation

  • 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


    Inheritance and Windows Forms - Carrying Out the Scenario


    (Page 4 of 5 )

    Well, here is the scenario that I want to carry out:

    1) I want to add a manager.
    2) I want to validate the user inputs.
    3) If the user inputs are valid, then I want to add the manager.

    The same scenario above should be valid for the technicians.

    The most logical way to carry out the previous scenario for the manager is to validate the inputs when the user clicks the “Add” (btnAdd). But if we handle it on the “ManageEmployees” form, then how should I determine if what I am adding is a Manager or a Technician? One of the answers will be to put an enum on the form and set it to the type of employees I am working with.

    Shouldn’t I check all the time about this enum, no matter what I do? We will thank the “ManageEmployees” form for giving us the common functionality and our “ManageManagers” form should be taking over from now on.

    But before we take over, we will be asking our nice “ManageEmployees” form a final request, that please, when you receive the click event of button “btnAdd” we want to handle that event.

    So, if you double click on the “btnAdd” on the “ManageEmployees” from the editor will open to this sub.


    Private Sub btnAdd_Click(ByVal sender As System.Object
    ByVal e 
    As System.EventArgsHandles btnAdd.Click
     
    End Sub

    As you can tell, the “btnAdd_Click” is private, and according to the Object Oriented principles, this means that the sub will be only available to the class itself.

    Should we stop here (for sure not!!) we will do a little change on this sub to look just like this:


    Protected Overridable Sub btnAdd_Click(ByVal 
    sender 
    As System.ObjectByVal e As 
    System
    .EventArgsHandles btnAdd.Click
     
    End Sub

    Now the sub looks much better. It is not only available to the “ManageEmployees” form only, but also to all the forms that are inheriting from the “ManageManagers” and “ManageTechnicians” (yes you are right, it is Protected). Above all, it is ready to be taken control off by the inheriting classes (it is Overridable).

    So let’s get back to our “ManageMangers” form, and let’s override the “BtnAdd_Click” sub. Let’s add the following to the “ManageManagers”:


    Protected Overrides Sub btnAdd_Click(ByVal sender 
    As System
    .ObjectByVal e As System.EventArgs
    'Handles btnAdd.Click
     
    End Sub

    More Visual Basic.NET Articles
    More By Mohammed Qattan


     

    VISUAL BASIC.NET ARTICLES

    - 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...
    - Creating and Drawing a Game Map in VB.NET (F...
    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT