Home

The Forms of an Application

 

Introduction

The form is the most fundamental object used in an application. By itself, a form does nothing. Its main role is to host other objects that the user uses to interact with the computer:

Introduction to Forms
     

Form Creation

There are various ways you can get a form to your application:

  • If you create a Windows Forms Application, it creates a starting form for you
  • After starting an empty project or a Windows Forms Application, you can add a form to it. To do this, on the main menu, you can click Project -> Add New Item... Select Windows Form. Give it a name and click OK
  • You can dynamically create a form and add it to your application.

In Lesson 2, we saw that a was based on the Form class that is defined in the System.Windows.Forms namespace created in the System.Windows.Forms.dll assembly. Therefore, if you start an application from scratch and you want to use a form in it, you can include the System.Windows.Forms.dll library to your application. To refer to a form, you can include the System.Windows.Forms namespace in your application.

As seen in Lesson 2, to create a form-based application, you can derive a class from Form. Here is an example:

Imports System.Windows.Forms

Module Exercise

    Public Class Starter
        Inherits Form

        Dim components As System.ComponentModel.Container

        Public Sub New()
            InitializeComponent()
        End Sub

        Public Sub InitializeComponent()

        End Sub

    End Class

    Function Main() As Integer

        Dim frmStart As Starter = New Starter

        Application.Run(frmStart)

        Return 0
    End Function

End Module

Practical LearningPractical Learning: Introducing Forms

  1. Start Microsoft Visual Basic and create a new Windows Application named CPAS1
  2. Press Ctrl + F5 to test the program
  3. Close the form and return to your programming environment

The Name of a Form

Like any other control, a form must have a name. If you derive a class from Form, the name you use for the class would be the name of the form. If you add a form from the Add New Item dialog box, you must also give it a name. If you create a Windows Application from the New Project dialog box, the wizard would create a default form for you named Form1. However you create or get a form, you can change its name.

To change the name of a form, in the Solution Explorer, right-click the name of the form and type a new name with the .cs extension.

Practical LearningPractical Learning: Renaming a Form

  1. In the Solution Explorer, right-click Form1.cs and click Rename
  2. Type Central.cs and press Enter

 

 

Home Copyright © 2008 FunctionX, Inc. Next