imports System
imports System.Drawing
imports System.Windows.Forms
public class InheritedForm : inherits BaseForm
private WithEvents btn as Button
public sub New()
Text = "Inherited Form"
btn = new Button()
btn.Location = new Point(25,150)
btn.Size = new Size(125,25)
btn.Text = "C&lose on Inherited"
Controls.Add(btn)
lbl.Text = "Now from InheritedForm"
end sub
Public Shadows Shared Sub Main()
Application.Run(new InheritedForm())
end sub
private sub btn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn.Click
Application.Exit()
end sub
protected Overrides Sub SomeMethod()
MessageBox.Show("This is the overridden SomeMethod called " + _
"from InheritedForm.")
end sub
end class
public class BaseForm : inherits System.Windows.Forms.Form
private WithEvents btnClose as Button
private WithEvents btnApp as Button
protected lbl as Label
public Sub New()
btnClose = new Button()
btnClose.Location = new Point(25,100)
btnClose.Size = new Size(100,25)
btnClose.Text = "&Close"
btnApp = new Button()
btnApp.Location = new Point(200,100)
btnApp.Size = new Size(150,25)
btnApp.Text = "&Base Application"
lbl = new Label()
lbl.Location = new Point(25,25)
lbl.Size = new Size(100,25)
lbl.Text = "This label on BaseForm"
Controls.AddRange(new Control(){lbl, btnClose, btnApp})
end sub
private sub btnClose_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnClose.Click
Application.Exit()
end sub
private sub btnApp_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnApp.Click
MessageBox.Show("This is the Base application.")
SomeMethod()
end sub
protected Overridable Sub SomeMethod()
MessageBox.Show("This is SomeMethod called from BaseForm.")
end sub
end class
|