VB.NET Windows Forms

Keyword Array Collections File String Cast Class Console Data Dictionary Enum Exception For If Interface Lambda LINQ List Nothing Number Process Property Regex Select Sort Split StringBuilder Structure Sub Time Windows

Window: Windows Forms

The Windows Forms platform supports Windows GUI programs. And the VB.NET language can be used to control these programs. We run arbitrary code as a result of event handlers. This section covers Windows Forms in the VB.NET language.


In Windows Forms, you add controls by dragging them to your form in Visual Studio. Then, you can double-click on those controls and add event handlers such as Form1_Load to your program.

Events:In an event handler, you can add your VB.NET statements to perform the actions you want.


TextBox:This program shows a TextBox control. When the containing Form loads, the TextBox is changed to display a message.


Button:This is another common Control in Windows Forms. A Button is often used with a TextBox on the same Form.

Based on:

.NET 4.5

Example Windows Forms program: VB.NET

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, _
			   ByVal e As System.EventArgs) Handles MyBase.Load
	Text = "Dot Net Perls"
	TextBox1.Text = "VB.NET is awesome!"
    End Sub
End Class


Exclamation mark

If you are using Windows Forms, the easiest way to show a dialog box or alert box is to call MessageBox.Show. This results in a customizable dialog window. This is easier than implementing a dialog yourself.


OpenFileDialog:The OpenFileDialog is a prebuilt control that handles selecting, and opening, files from the file system.




The BackgroundWorker is an easy way to use threads in your VB.NET program. We can set it up directly in the Visual Studio Windows Forms designer. With it, we can create threads to avoid freezing the interface.


Tip:Threading is hard to implement correctly. Generally I recommend using BackgroundWorker to add threading where it is needed.



With DataGridView, you can display your tabular data in a variety of ways. The DataGridView is much faster to deploy and more efficient at runtime than most other solutions in Windows Forms for its intended use.


Note:The DataGridView is an important control. It is hard to start using. But it can also improve a program a great deal.


The VB.NET programming language

Windows Forms is one of the fastest ways to develop a usable graphical user interface with the VB.NET language. By dragging controls in Visual Studio, we develop interactive applications and hook up event handlers.