Form Inheritance : Form « GUI « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » GUI » Form 
14.49.8.Form Inheritance
Form Inheritance
Imports System.Windows.Forms

public class FormInheritance
   public Shared Sub Main
        Application.Run(New Startup)
   End Sub
End class


Public Class Startup
    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

    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 NothingThen
                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 Button2 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(4848)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "BaseForm"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(15248)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(8823)
Me.Button2.TabIndex = 1
Me.Button2.Text = "InheritedForm"
'
'Startup
'
Me.AutoScaleBaseSize = New System.Drawing.Size(513)
Me.ClientSize = New System.Drawing.Size(292273)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button2, Me.Button1})
Me.Name = "Startup"
Me.Text = "Startup"
Me.ResumeLayout(False)

   End Sub

#End Region

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Button1.Click
    dim frm1 as new BaseForm()
    frm1.Show()
  End Sub

  Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Button2.Click
    dim frm2 as new InheritedForm()
    frm2.Show()
  End Sub
End Class


Public Class BaseForm 
    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

    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 NothingThen
                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.
  Protected WithEvents lblHeading As System.Windows.Forms.Label
  Protected WithEvents btn As System.Windows.Forms.Button
  Protected WithEvents lblOutput As System.Windows.Forms.Label
  Private WithEvents Label3 As System.Windows.Forms.Label
  Private WithEvents Label2 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
Me.lblHeading = New System.Windows.Forms.Label()
Me.btn = New System.Windows.Forms.Button()
Me.lblOutput = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'lblHeading
'
Me.lblHeading.Font = New System.Drawing.Font("Microsoft Sans Serif"15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lblHeading.Location = New System.Drawing.Point(2416)
Me.lblHeading.Name = "lblHeading"
Me.lblHeading.Size = New System.Drawing.Size(24823)
Me.lblHeading.TabIndex = 0
Me.lblHeading.Text = "Base Form"
Me.lblHeading.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'btn
'
Me.btn.Location = New System.Drawing.Point(9672)
Me.btn.Name = "btn"
Me.btn.TabIndex = 1
Me.btn.Text = "Time"
'
'lblOutput
'
Me.lblOutput.Location = New System.Drawing.Point(64128)
Me.lblOutput.Name = "lblOutput"
Me.lblOutput.Size = New System.Drawing.Size(13623)
Me.lblOutput.TabIndex = 2
Me.lblOutput.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(80200)
Me.Label3.Name = "Label3"
Me.Label3.TabIndex = 3
Me.Label3.Text = "Base Form"
Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(40232)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(21623)
Me.Label2.TabIndex = 4
Me.Label2.Text = "Created in Visual Studio .NET"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'BaseForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(513)
Me.ClientSize = New System.Drawing.Size(292273)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label2, Me.Label3, Me.lblOutput, Me.btn, Me.lblHeading})
Me.Name = "BaseForm"
Me.Text = "Visual Form Inheritance"
Me.ResumeLayout(False)

   End Sub

#End Region

  Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles btn.Click
    lblOutput.Text = "The time is: " + DateTime.Now.ToString("T")
  End Sub
End Class




Public Class InheritedForm
    Inherits BaseForm

#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
      btn.Text = "Date"
      lblHeading.Text = "Inherited Form"

    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 NothingThen
                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.
    <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
Me.SuspendLayout()
'
'lblHeading
'
Me.lblHeading.BackColor = System.Drawing.Color.Yellow
Me.lblHeading.Visible = True
'
'btn
'
Me.btn.BackColor = System.Drawing.Color.Yellow
Me.btn.Visible = True
'
'lblOutput
'
Me.lblOutput.BackColor = System.Drawing.Color.Yellow
Me.lblOutput.Visible = True
'
'InheritedForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(513)
Me.BackColor = System.Drawing.Color.Yellow
Me.ClientSize = New System.Drawing.Size(292273)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblOutput, Me.btn, Me.lblHeading})
Me.Name = "InheritedForm"
Me.ResumeLayout(False)

   End Sub

#End Region

  Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles btn.Click
      lblOutput.Text = "Today is: " + DateTime.Now.ToString("D")
  End Sub

End Class
14.49.Form
14.49.1.Create Form window by hand
14.49.2.Add control to Form dynamicallyAdd control to Form dynamically
14.49.3.Set Form IconSet Form Icon
14.49.4.Form Fade outForm Fade out
14.49.5.Border Less formBorder Less form
14.49.6.Owner draw form
14.49.7.Build Form hierarchicallyBuild Form hierarchically
14.49.8.Form InheritanceForm Inheritance
14.49.9.SendKeysSendKeys
14.49.10.Form: show, hide and get data fromForm: show, hide and get data from
14.49.11.Auto Scroll FormAuto Scroll Form
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.