Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Power of Visual Inheritance in .NET – “Best”

, 4 Dec 2003
This article helps in exploring the power of Visual Inheritance and makes your application development very easy.
Public Class PMainForm
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        If Position = 0 Then Position = 100
    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    '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

    Protected Friend WithEvents BParent As System.Windows.Forms.Button
    Protected Friend WithEvents NavPanel As System.Windows.Forms.Panel
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.NavPanel = New System.Windows.Forms.Panel()
        Me.BParent = New System.Windows.Forms.Button()
        Me.NavCaption = New System.Windows.Forms.Label()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.PBNavPrev = New System.Windows.Forms.Button()
        Me.NavPanel.SuspendLayout()
        Me.SuspendLayout()
        '
        'NavPanel
        '
        Me.NavPanel.BackColor = System.Drawing.Color.FromArgb(CType(224, Byte), CType(224, Byte), CType(224, Byte))
        Me.NavPanel.Controls.AddRange(New System.Windows.Forms.Control() {Me.BParent, Me.NavCaption, Me.Button1, Me.PBNavPrev})
        Me.NavPanel.Dock = System.Windows.Forms.DockStyle.Top
        Me.NavPanel.Name = "NavPanel"
        Me.NavPanel.Size = New System.Drawing.Size(292, 80)
        Me.NavPanel.TabIndex = 1
        '
        'BParent
        '
        Me.BParent.Location = New System.Drawing.Point(192, 40)
        Me.BParent.Name = "BParent"
        Me.BParent.Size = New System.Drawing.Size(72, 24)
        Me.BParent.TabIndex = 5
        Me.BParent.Text = "Parent"
        '
        'NavCaption
        '
        Me.NavCaption.Font = New System.Drawing.Font("Trebuchet MS", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.NavCaption.Location = New System.Drawing.Point(16, 8)
        Me.NavCaption.Name = "NavCaption"
        Me.NavCaption.Size = New System.Drawing.Size(232, 24)
        Me.NavCaption.TabIndex = 4
        Me.NavCaption.Text = "Navigation Panel"
        '
        'Button1
        '
        Me.Button1.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(64, Byte), CType(0, Byte))
        Me.Button1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Button1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Button1.Location = New System.Drawing.Point(96, 40)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(32, 23)
        Me.Button1.TabIndex = 3
        Me.Button1.Text = ">>"
        '
        'PBNavPrev
        '
        Me.PBNavPrev.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(64, Byte), CType(0, Byte))
        Me.PBNavPrev.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.PBNavPrev.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.PBNavPrev.Location = New System.Drawing.Point(48, 40)
        Me.PBNavPrev.Name = "PBNavPrev"
        Me.PBNavPrev.Size = New System.Drawing.Size(32, 23)
        Me.PBNavPrev.TabIndex = 2
        Me.PBNavPrev.Text = "<<"
        '
        'PMainForm
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.White
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.NavPanel})
        Me.Name = "PMainForm"
        Me.Text = "Main Parent Form"
        Me.NavPanel.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    'Implementation in the Parent Form
    Private Sub PBNavPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PBNavPrev.Click
        Try
            Position = Position - 1
            InfoLabel.Text = "Move Previous " & (Position).ToString

        Catch e1 As Exception
            MsgBox(e1.Source & " : " & e1.Message)
        End Try
    End Sub

    'Implementation in the Parent Form
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Position = Position + 1
            InfoLabel.Text = "Move Next " & (Position).ToString

        Catch e1 As Exception
            MsgBox(e1.Source & " : " & e1.Message)
        End Try
    End Sub


#Region "Custom Properties of the {Parent Form)"
    'InfoLabel Property 
    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

    'CurrentPosition Property
    Dim LPosition As Long
    Protected Property Position() As Long
        Get
            Return LPosition
        End Get
        Set(ByVal Value As Long)
            LPosition = Value
        End Set
    End Property

#End Region

    'How to share the implementation of the Parent Form
    Protected Friend Overridable Sub BParent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BParent.Click
        MsgBox("Functionality of Parent is used.")
    End Sub

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Saurabhdotnet
Web Developer
India India
Saurabh Verma works as an Architect, possessing over 10 years designing and developing software and currently assists product companies to scale and writing flexible software. He has vast experience in designing Web 2.0 solutions using Microsoft Technologies; WF, WCF and AJAX.ASP.NET, and practicing AGILE Methodologies and Domain Driven Design for the implementation. He likes to perform superbike stunts in his free time. Smile | :)
 
He has been awarded Microsoft Most Valuable Professional, MCSD.NET, MCAD.NET, MCDBA and Microsoft Web Rock Star 2007.
 
He maintains his blog at http://www.domaindrivendesign.info for all the aspiring architects and developers.
 
You can reach him at saurabhdotnet@hotmail.com

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 5 Dec 2003
Article Copyright 2003 by Saurabhdotnet
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid