Array Class Collections File String Cast Console Data Directive Enum Exception If Interface Lambda LINQ Loop Nothing Number Process Property Regex Sort StringBuilder Structure Sub Time Windows
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.TextBox
Button:This is another common Control in Windows Forms. A Button is often used with a TextBox on the same Form.Button
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
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.MessageBox.Show
OpenFileDialog:The OpenFileDialog is a prebuilt control that handles selecting, and opening, files from the file system.OpenFileDialog
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.BackgroundWorker
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.DataGridView
Note:The DataGridView is an important control.
It is hard to start using.
But it can also improve a program a great deal.
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.