Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 5 - 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 - Explanation


    (Page 5 of 5 )

    As you can tell, we overrode the sub in the base class. So that when the user click the “Add” button, on the “ManageEmployee” form, our “ManageManagers” form will take over, and do its work. Note that we commented the “Handles btnAdd.Click.” Why?

    Good question. Remember that we are overriding a sub in the parent class, and the event is being captured on the parent class, so in the child class we don’t receive the event. Rather, it is being received by the parent class.

    Since the first thing we want to do before creating a new manager is to validate the user inputs, and since the function that validates the user inputs is in the parent class “ManageEmployees”, then we will call our parent “IsValidInputs” which will determine if the inputs are valid and if we can go on with our work. So the “btnAdd_Click” sub will just look as beautiful as this:


    Protected Overrides Sub btnAdd_Click(ByVal 
    sender 
    As System.ObjectByVal e As 
    System
    .EventArgs'Handles btnAdd.Click
         Dim oManager As Manager
         Try
             If IsValidInputs() Then
                 oManager = New Manager(MyBase.txtName.ToString,
    Integer.Parse(MyBase.txtAge.ToString))
             End If
         Catch oException As Exception
             '
    Handle any unexpected errors here
         End Try
     End Sub

    Always remember that any change on the parent form “ManageEmployee” should be followed by a “Build” to the project in order to carry out the changes on the inheriting forms.

    This is just a glance on how to use the windows forms and the inheritance between forms: we wrote the general code on a parent form, and then used it with the child forms. Now if we want to add more fields, add extra functionality, change some logic, or even play with the properties of the form - so we only need to change it on the parent form - build the project, and the changes will automatically be reflected on the children forms.


    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.

     

    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 2 hosted by Hostway
    Stay green...Green IT