Build Form hierarchically : Form « GUI « VB.Net Tutorial






Build Form hierarchically
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








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