Visual Basic .NET - Forms
In VB.NET, a form is a visual interface that allows the user to interact with the program. Events are actions that trigger specific actions in response, such as clicking a button or resizing a form. Methods are the procedures that the program uses to handle events or carry out specific actions.
To create a new form in VB.NET, you can use the following steps:
- Open Visual Studio and create a new project
- From the Solution Explorer, right-click on the project name and select Add > Windows Form
- The new form will appear in the Designer window, where you can add controls and design the layout.
Properties:
- Text: This property sets the text displayed in the title bar of the form.
- BackColor: This property sets the background color of the form.
- ForeColor: This property sets the foreground color of the form.
- Font: This property sets the font used for text displayed on the form.
- Size: This property sets the size of the form in pixels.
- StartPosition: This property sets the initial position of the form when it is displayed.
- FormBorderStyle: This property sets the style of the border of the form.
- Icon: This property sets the icon displayed in the title bar of the form.
- MaximizeBox: This property determines whether the form can be maximized.
- MinimizeBox: This property determines whether the form can be minimized.
- ControlBox: This property determines whether the control box (the set of buttons in the title bar of the form) is displayed.
- ShowInTaskbar: This property determines whether the form is displayed in the taskbar.
- TopMost: This property determines whether the form is displayed as a top-most form.
- Opacity: This property sets the opacity of the form.
Methods:
- Show(): Displays the form on the screen.
- Hide(): Hides the form from the screen.
- Close(): Closes the form.
- Dispose(): Releases all resources used by the form.
- BringToFront(): Brings the form to the front of the z-order.
- SendToBack(): Sends the form to the back of the z-order.
- Activate(): Activates the form and gives it focus.
- Refresh(): Forces the form to redraw itself.
- SetBounds(): Sets the size and position of the form.
- SetDesktopLocation(): Sets the location of the form relative to the desktop.
These are just a few of the many methods available for a Form object in VB.NET. Each method has its own use and purpose, and can be used to perform various operations on a form object.
In VB.NET, a form goes through several stages in its life cycle. These stages are:
- Creation: The form is created using the New keyword or the CreateForm method.
- Loading: The form is loaded into memory and the Load event is raised.
- Shown: The form is displayed on the screen and the Shown event is raised.
- Activation: The form becomes the active form and the Activated event is raised.
- Deactivation: The form is no longer the active form and the Deactivated event is raised.
- Closing: The form is being closed and the Closing event is raised.
- Closed: The form is closed and the Closed event is raised.
- Disposed: The form is disposed of and the Disposed event is raised.
During each of these stages, different events are raised, and different properties and methods can be accessed to perform various actions on the form. It is important to handle these events properly to ensure that the form behaves as expected and that any resources are released when they are no longer needed.