VB.Net
  Home arrow VB.Net arrow Page 5 - Everything You Wanted to Know About Forms ...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
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? 
VB.NET

Everything You Wanted to Know About Forms Inheritance in VB.Net
By: Saurabh Verma
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 189
    2003-10-29

    Table of Contents:
  • Everything You Wanted to Know About Forms Inheritance in VB.Net
  • Concept of Inheritance
  • Visual Inheritance
  • What’s New in This Article
  • What's New in This Article, Cont'd
  • Conclusion

  • 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


    Everything You Wanted to Know About Forms Inheritance in VB.Net - What's New in This Article, Cont'd


    (Page 5 of 6 )

    4) How you change the properties of the controls from the parent form, which are not in the parent form (i.e. they are in the Child forms)

    Open the Parent Form define a property which accepts <Control> as return type.

        'InfoLabel Property (Control which we want to use from the child form)
        Dim localLabel As Label
        Protected Property InfoLabel() As Label
            Get
                Return localLabel
            End Get
            Set(ByVal Value As Label)
                localLabel = Value
            End Set
        End Property

    Now, open the child form. Place the control, which you want to use with the Parent Form. Change the ControlProperty from the Child Form for the parent form, in any event of the child form. For this example I have done this in the load event of the child form.

    Private Sub CForm3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.InfoLabel = Label1 'Control to be controlled by the Parent Form
            Me.Position = 99
    End Sub

    5) How to override the functionality of the Parent form from the Child Form

    Override the function of the parent form, which handles the particular functionality (for example, the click event of the button in the parent form).

    If you copy and paste that function from the Parent Form, please don’t forget to add the Shadows Attribute, for suppressing the function of the Parent Form (Note: when we use the Shadows keyword, then there is no need to use the Overridable keyword in the Parent Form for that function).

    Parent Form:

    Child Form:
    'Overiding the implementation of the Parent Form
    'please don't forget to remove the handles keyword from the last while
    'implementing in the child form

    Protected Friend Overrides Sub BParent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    MsgBox("Functionality of Child is used.")
    End Sub

    Or

    Protected Friend Shadows Sub BParent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    MsgBox("Functionality of Child is used.")
    End Sub

    6) How to change the properties of the inherited controls at design time (i.e. how to reposition the controls, set different properties, etc.)

    This is one of the main problems when we inherit any ParentForm – trust me, its very simple. Change the Modifiers property of the control, we want to control from the Child Form from Friend to Protected Friend.


    Protected Friend will be not listed there, so please take a deep breath and perform the following steps:


    1) Open the Code Window for the Parent Form.
    2) Expand "Windows Form Designer generated code" section.
    3) Find InitializeComponent() function.

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    4) Above this function you will find the initialization code for the controls which we have been placed into the form. They will be like:

    'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer. 
        'Do not modify it using the code editor.
        Friend WithEvents Button1 As System.Windows.Forms.Button
        Friend WithEvents PBNavPrev As System.Windows.Forms.Button
        Friend WithEvents NavCaption As System.Windows.Forms.Label

        Friend WithEvents BParent As System.Windows.Forms.Button
        Friend WithEvents NavPanel As System.Windows.Forms.Panel
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    Change the access modifiers of the control to Protected Friend for sharing them in the child form.

    5) 

    'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer. 
        'Do not modify it using the code editor.
        Protected Friend WithEvents Button1 As System.Windows.Forms.Button
        Protected Friend WithEvents PBNavPrev As System.Windows.Forms.Button
        Protected Friend WithEvents NavCaption As System.Windows.Forms.Label

        Protected Friend WithEvents BParent As System.Windows.Forms.Button
        Protected Friend WithEvents NavPanel As System.Windows.Forms.Panel
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    More VB.Net Articles
    More By Saurabh Verma


     

    VB.NET ARTICLES

    - MyClass - Implementing Polymorphism in VB.Net
    - Building a News Ticker Using VB.Net
    - Everything You Wanted to Know About Forms In...
    - Building Assemblies with VB.Net
    - Simple VB.NET Notify Icon with Panel Applica...
    - Regular Expressions in .NET
    - String Encryption With Visual Basic .NET
    - Deploying Applications in VB.NET: Part 1/2
    - Watching Folder Activity in VB.NET
    - Creating A Windows Service in VB.NET
    - Implementing The Google Web Service In VB.NET
    - Migrating to Visual Basic.NET from Visual Ba...







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