VB.Net/GUI/Control Inheritance
Add components to inherited form
Imports System
Imports System.Collections
Imports System.ruponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Configuration
Imports System.Resources
Imports System.Drawing
Imports System.Drawing.Drawing2D
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 Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.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 menuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents fileExitMenuItem As System.Windows.Forms.MenuItem
Protected WithEvents statusBar As System.Windows.Forms.StatusBar
Friend WithEvents menuItem3 As System.Windows.Forms.MenuItem
Friend WithEvents helpAboutMenuItem As System.Windows.Forms.MenuItem
Friend WithEvents mainMenu1 As System.Windows.Forms.MainMenu
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.menuItem1 = New System.Windows.Forms.MenuItem()
Me.fileExitMenuItem = New System.Windows.Forms.MenuItem()
Me.statusBar = New System.Windows.Forms.StatusBar()
Me.menuItem3 = New System.Windows.Forms.MenuItem()
Me.helpAboutMenuItem = New System.Windows.Forms.MenuItem()
Me.mainMenu1 = New System.Windows.Forms.MainMenu()
Me.SuspendLayout()
"
"menuItem1
"
Me.menuItem1.Index = 0
Me.menuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.fileExitMenuItem})
Me.menuItem1.Text = "&File"
"
"fileExitMenuItem
"
Me.fileExitMenuItem.Index = 0
Me.fileExitMenuItem.Text = "E&xit"
"
"statusBar
"
Me.statusBar.Location = New System.Drawing.Point(0, 72)
Me.statusBar.Name = "statusBar"
Me.statusBar.Size = New System.Drawing.Size(176, 22)
Me.statusBar.TabIndex = 1
Me.statusBar.Text = "Ready"
"
"menuItem3
"
Me.menuItem3.Index = 1
Me.menuItem3.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.helpAboutMenuItem})
Me.menuItem3.Text = "&Help"
"
"helpAboutMenuItem
"
Me.helpAboutMenuItem.Index = 0
Me.helpAboutMenuItem.Text = "&About..."
"
"mainMenu1
"
Me.mainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.menuItem1, Me.menuItem3})
"
"BaseForm
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(176, 94)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.statusBar})
Me.Menu = Me.mainMenu1
Me.Name = "BaseForm"
Me.Text = "BaseForm"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub fileExitMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles fileExitMenuItem.Click
Me.Close()
End Sub
Private Sub helpAboutMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles helpAboutMenuItem.Click
MessageBox.Show("Message?", "About")
End Sub
End Class
Public Class ExplorerForm
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
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.ruponentModel.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 treeView1 As System.Windows.Forms.TreeView
Friend WithEvents splitter1 As System.Windows.Forms.Splitter
Friend WithEvents listView1 As System.Windows.Forms.ListView
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim ListViewItem1 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New System.Windows.Forms.ListViewItem.ListViewSubItem() {New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "-Derives from BaseForm", System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)))}, -1)
Dim ListViewItem2 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New System.Windows.Forms.ListViewItem.ListViewSubItem() {New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "-Overrides Text property", System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)))}, -1)
Dim ListViewItem3 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New System.Windows.Forms.ListViewItem.ListViewSubItem() {New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "-Overrides Size property", System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)))}, -1)
Dim ListViewItem4 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New System.Windows.Forms.ListViewItem.ListViewSubItem() {New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "-Adds a TreeView control", System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)))}, -1)
Dim ListViewItem5 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New System.Windows.Forms.ListViewItem.ListViewSubItem() {New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "-Adds a Splitter control", System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)))}, -1)
Dim ListViewItem6 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New System.Windows.Forms.ListViewItem.ListViewSubItem() {New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "-Adds a ListView control", System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)))}, -1)
Me.treeView1 = New System.Windows.Forms.TreeView()
Me.splitter1 = New System.Windows.Forms.Splitter()
Me.listView1 = New System.Windows.Forms.ListView()
Me.SuspendLayout()
"
"statusBar
"
Me.statusBar.Location = New System.Drawing.Point(0, 123)
Me.statusBar.Size = New System.Drawing.Size(280, 22)
Me.statusBar.Visible = True
"
"treeView1
"
Me.treeView1.Dock = System.Windows.Forms.DockStyle.Left
Me.treeView1.ImageIndex = -1
Me.treeView1.Name = "treeView1"
Me.treeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node0"), New System.Windows.Forms.TreeNode("Node1", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node4", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node5", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node6")})})}), New System.Windows.Forms.TreeNode("Node2"), New System.Windows.Forms.TreeNode("Node3")})
Me.treeView1.SelectedImageIndex = -1
Me.treeView1.Size = New System.Drawing.Size(121, 123)
Me.treeView1.TabIndex = 2
"
"splitter1
"
Me.splitter1.Location = New System.Drawing.Point(121, 0)
Me.splitter1.Name = "splitter1"
Me.splitter1.Size = New System.Drawing.Size(3, 123)
Me.splitter1.TabIndex = 3
Me.splitter1.TabStop = False
"
"listView1
"
Me.listView1.Dock = System.Windows.Forms.DockStyle.Fill
Me.listView1.Items.AddRange(New System.Windows.Forms.ListViewItem() {ListViewItem1, ListViewItem2, ListViewItem3, ListViewItem4, ListViewItem5, ListViewItem6})
Me.listView1.Location = New System.Drawing.Point(124, 0)
Me.listView1.Name = "listView1"
Me.listView1.Size = New System.Drawing.Size(156, 123)
Me.listView1.TabIndex = 4
Me.listView1.View = System.Windows.Forms.View.List
"
"ExplorerForm
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(280, 145)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.listView1, Me.splitter1, Me.treeView1, Me.statusBar})
Me.Name = "ExplorerForm"
Me.ResumeLayout(False)
End Sub
#End Region
End Class
Public Class MainClass
Shared Sub Main()
Dim myform As Form = New ExplorerForm()
Application.Run(myform)
End Sub
End Class
Inherits from Base Form
Imports System
Imports System.Collections
Imports System.ruponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Configuration
Imports System.Resources
Imports System.Drawing
Imports System.Drawing.Drawing2D
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 Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.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 menuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents fileExitMenuItem As System.Windows.Forms.MenuItem
Protected WithEvents statusBar As System.Windows.Forms.StatusBar
Friend WithEvents menuItem3 As System.Windows.Forms.MenuItem
Friend WithEvents helpAboutMenuItem As System.Windows.Forms.MenuItem
Friend WithEvents mainMenu1 As System.Windows.Forms.MainMenu
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.menuItem1 = New System.Windows.Forms.MenuItem()
Me.fileExitMenuItem = New System.Windows.Forms.MenuItem()
Me.statusBar = New System.Windows.Forms.StatusBar()
Me.menuItem3 = New System.Windows.Forms.MenuItem()
Me.helpAboutMenuItem = New System.Windows.Forms.MenuItem()
Me.mainMenu1 = New System.Windows.Forms.MainMenu()
Me.SuspendLayout()
"
"menuItem1
"
Me.menuItem1.Index = 0
Me.menuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.fileExitMenuItem})
Me.menuItem1.Text = "&File"
"
"fileExitMenuItem
"
Me.fileExitMenuItem.Index = 0
Me.fileExitMenuItem.Text = "E&xit"
"
"statusBar
"
Me.statusBar.Location = New System.Drawing.Point(0, 72)
Me.statusBar.Name = "statusBar"
Me.statusBar.Size = New System.Drawing.Size(176, 22)
Me.statusBar.TabIndex = 1
Me.statusBar.Text = "Ready"
"
"menuItem3
"
Me.menuItem3.Index = 1
Me.menuItem3.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.helpAboutMenuItem})
Me.menuItem3.Text = "&Help"
"
"helpAboutMenuItem
"
Me.helpAboutMenuItem.Index = 0
Me.helpAboutMenuItem.Text = "&About..."
"
"mainMenu1
"
Me.mainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.menuItem1, Me.menuItem3})
"
"BaseForm
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(176, 94)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.statusBar})
Me.Menu = Me.mainMenu1
Me.Name = "BaseForm"
Me.Text = "BaseForm"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub fileExitMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles fileExitMenuItem.Click
Me.Close()
End Sub
Private Sub helpAboutMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles helpAboutMenuItem.Click
MessageBox.Show("Message?", "About")
End Sub
End Class
Public Class EditorForm
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
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.ruponentModel.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 textBox1 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.textBox1 = New System.Windows.Forms.TextBox()
Me.SuspendLayout()
"
"statusBar
"
Me.statusBar.Location = New System.Drawing.Point(0, 71)
Me.statusBar.Text = "Text on a status bar"
Me.statusBar.Visible = True
"
"textBox1
"
Me.textBox1.Dock = System.Windows.Forms.DockStyle.Fill
Me.textBox1.Multiline = True
Me.textBox1.Name = "textBox1"
Me.textBox1.Size = New System.Drawing.Size(176, 71)
Me.textBox1.TabIndex = 2
Me.textBox1.Text = "Text in a text box."
"
"EditorForm
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(176, 93)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.textBox1, Me.statusBar})
Me.Name = "EditorForm"
Me.Text = "EditorForm"
Me.ResumeLayout(False)
End Sub
#End Region
End Class
Public Class MainClass
Shared Sub Main()
Dim myform As Form = New EditorForm()
Application.Run(myform)
End Sub
End Class