Build Form hierarchically : 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.7.Build Form hierarchically
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 EventArgsHandles 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 EventArgsHandles btnClose.Click
    Application.Exit()
  end sub

  private sub btnApp_Click(ByVal sender As Object, ByVal e As EventArgsHandles 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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.