Home arrow VB.Net arrow Page 5 - Everything You Wanted to Know About Forms Inheritance in VB.Net
VB.NET

Everything You Wanted to Know About Forms Inheritance in VB.Net


Learn how to take advantage of Forms Inheritance, while being introduced to certain Object Oriented approaches, in Saurabh's latest article.

Author Info:
By: Saurabh Verma
Rating: 4 stars4 stars4 stars4 stars4 stars / 215
October 29, 2003
TABLE OF CONTENTS:
  1. · Everything You Wanted to Know About Forms Inheritance in VB.Net
  2. · Concept of Inheritance
  3. · Visual Inheritance
  4. · Whatís New in This Article
  5. · What's New in This Article, Cont'd
  6. · Conclusion

print this article
SEARCH DEVARTICLES

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()


blog comments powered by Disqus
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...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials