Windows Forms
Overview of how windows forms are created
Generally, when we talk about a windows application, we imagine a rectangular screen with controls in it. This rectangular screen is known as windows form or WinForm. We can think of a form as a container that contains different controls.
Whenever we start a new windows application project, a form is added to our project by default. The name of this form is Form1. Later on, we can add more forms to our project if needed.
Like other controls, the forms have properties and events too. Using the properties of the form, we can specify how it will look when the application runs. Here are some of the important properties of form:
|
(Name) |
Use to access the form programmatically (in code). |
|
Text |
The text to display on the title bar. |
|
BackColor |
Background color of the form. |
|
Icon |
The icon of the form, generally the application's icon. |
|
ControlBox |
To specify if the control box will be displayed or not. |
|
MaximizeBox |
To specify if the maximize button will be displayed or not. |
|
MinimizeBox |
To specify if the minimize button will be displayed or not. |
|
FormBorderStyle |
To set the style of the border. |
|
Size -Width -Height |
To specify the width and height of the form. These can also be adjusted visually by dragging the borders of the form. |
|
WindowState |
To specify if the form will start in a maximized, minimized or normal state. |
A form also has many events. Most important of them is the Load event that occurs when the user loads the form during application execution.
A form in itself cannot do much and we need to add controls to it, set their properties and write code for their events in order to create a useful application. We can add controls to the form by dragging them from the Toolbox and dropping on the form. We can also double click a control in the Toolbox to add it to the form. Once a control has been added to the form, we can click on it to select it. We can move the control to other location on the form and we can resize it just like we resize a window.
In the rest of this chapter, we will learn about some commonly used controls, their properties and events. We will create simple applications to understand how these controls work.
