VB.NET Forms - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

VB.NET Forms

Description:

Cohesion is the degree to the which the parts (statements) of a module are ... High cohesion and low coupling are desirable. To make software easy to maintain ... – PowerPoint PPT presentation

Number of Views:26
Avg rating:3.0/5.0
Slides: 13
Provided by: cisUso
Category:
Tags: net | cohesion | forms

less

Transcript and Presenter's Notes

Title: VB.NET Forms


1
VB.NET Forms
  • ITE 370

2
Forms Class
  • Forms are part of the Windows Form class defined
    in the .NET Framework Class Library
  • A form is a container for controls a form is
    used to design a GUI-based window in a Windows
    application
  • A form displays information and receives input
    from the user
  • Always orient a form at a task as defined by the
    user

Public Class Form1 Inherits
System.Windows.Forms.Form End Class Form1
3
Form Properties
  • Text defines the text to display in the caption
    bar
  • StartPosition determines position of form when
    it first appears (eg. CenterScreen)
  • Size.Width, Size.Height the 2D area occupied by
    the form, in units of pixels
  • Location.X, Location.Y the relative position of
    the form on the screen
  • FormBorderStyle determines the appearance and
    behavior of the borders of the form

4
Displaying a Form at Startup
  • Startup Form for project loads shows
    automatically
  • Or, use a Sub Main in a separate module to show
    initial form
  • Module Main
  • Sub Main()
  • ' declare form to display baseball teams
  • Dim fTeam As fTeams
  • fTeam New fTeams()
  • Application.Run(fTeam)
  • End Sub
  • End Module

5
Form Display
  • Showing a form
  • Form1.Show() displays Form1
  • Form1.ShowDialog() modally
  • Closing a form in code
  • Me.Close()

6
Cohesion and coupling
  • Recall the principles of modular programming
  • Cohesion is the degree to the which the parts
    (statements) of a module are interrelated, that
    is, they all contribute to doing one thing
  • Coupling is the degree to which two modules
    interact, or are interrelated.
  • High cohesion and low coupling are desirable
  • To make software easy to maintain
  • To reduce the possibility of errors
  • For better fault detection and isolation

7
Forms interaction and low coupling
  • When one form calls (to display) another,
  • Pass information back-and-forth through the
    constructor or public properties, not global
    variables, like control names
  • Private Sub btnHello_Click(ByVal sender As
    System.Object, _
  • ByVal e As System.EventArgs) Handles
    btnHello.Click
  • ' declare and initialize a new form object,
    passing
  • the user name to be displayed on the called
    form
  • Dim fHello1 As New fHello(txtUserName.Text)
  • fHello1.ShowDialog() ' display form
    fHello1 modally
  • fHello1.Close()
  • fHello1.Dispose()
  • End Sub

8
Form constructor
  • Dim mUserName As String ' instance variable
  • Public Sub New(ByVal UName As String)
  • MyBase.New()
  • 'This call is required by the Windows
    Form Designer.
  • InitializeComponent()
  • 'Add any initialization after the
    InitializeComponent() call
  • mUserName UName
  • lblUserName.Text "Hello, " mUserName
  • End Sub

9
User-defined property in form class
  • Public Property UserName() As String
  • Get
  • Return mUserName
  • End Get
  • Set(ByVal Value As String)
  • mUserName Value
  • lblUserName.Text mUserName
  • End Set
  • End Property
  • End Class

10
Form Visibility
  • Make form visible
  • fEdit.Visible True
  • fMainMenu.Show
  • Make form invisiblefMainMenu.Visible False
  • Me.Visible False
  • Me.Hide

11
Form Enabling and Disabling
  • Enable form
  • fMain.Enabled True
  • Disable form
  • fMain.Enabled False
  • Me.Enabled False

12
Form Events
  • Form1_Load() - occurs before a form is displayed
    for the first time.
  • Form1_Activated() -- ... Occurs form becomes the
    active window through code or by user
  • Form1_Deactivate() - ... occurs when the form
    loses focus and is not the active form
Write a Comment
User Comments (0)
About PowerShow.com