Net-informations.com
SiteMap  | About    

Windows Forms

VB.Net programmers have made extensive use of forms to build user interfaces. Each time you create a Windows application, Visual Studio will display a default blank form, onto which you can drag and drop controls from the Visual Studio Toolbox window.

how to vb.net form

The first step is to start a new project and build a form. Open your Visual Studio and select File->NewProject and select Visual Basic from the New project dialog box and select Windows Froms Application. Enter your project name instead of WindowsApplication1 in the bottom of dialouge box and click OK button. The following picture shows how to crate a new Form in Visual Studio.

vb.net new project

Select project type from New project dialog Box

new vb.net application

When you add a Windows Form to your project, many of the forms properties are set by default. Although these values are convenient, they will not always suit your programming needs. The following picture shows how is the default Form look like.

vb.net new form

At the top of the form there is a title bar which displays the forms title. Form1 is the default name, you can change the name to your convenience . The title bar also includes the control box, which holds the minimize, maximize, and close buttons.

If you want to set any properties of the Form, you can use Visual Studio Property window to change it.

vb.net form properties

For example , to change the forms title from Form1 to MyForm, click on Form1 and move to the right side down Properties window, set Text property to MyForm. Then you can see the Title of the form is changed. Likewise you can set any properties of Form through Properties window.

You can also set the properties of the Form1 through coding. For coding, you should right-click the design surface or code window and then clicking View Code.

vb.net view source code

When you right click on Form then you will get code behind window, there you can write your code.

For example , if you want to change the back color of the form to Brown , you can code like this.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.BackColor = Color.Brown End Sub

Likwise you can change other properties of Form1 through coding.

The following VB.Net source code shows how to change the Title, BackColor, Size, Location and MaximizeBox properties of Form1. Copy and paste the following VB.Net source code to source code editor of your Visual Studio.




Public Class Form1
	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

		Me.Text = "Change Prperties Through Coding"
		Me.BackColor = Color.Brown
		Me.Size = New Size(350, 125)
		Me.Location = New Point(300, 300)
		Me.MaximizeBox = False

	End Sub
End Class

When you execute (press F5 key) the program the form is look like the following image.
vb-form-output.jpg


The Windows based programs you create using Visual Basic .NET run in the context of a form. When you close the form, the application also ends.


 VB.Net GUI - Related Contents