Understanding the Form Class using VB.NET

In this article I will explain you about the Form Class using VB.NET.
  • 2312

The main window of your Windows application is a form, derived from the ContainerControl class. A form is a representation of a window in .NET. You can use the Form class to create Single Document Interface (SDI), Multiple Document Interface (MDI), and dialog-based applications. The windows can be borderless, transparent, and floating. You can create an MDI form by setting the IsMDIContainer property to true. To make a form an MDI child, set the MdiParent property with a reference to the MDI container form. To display the child, the child form's Show method must be called or its Visible property set to true.

You can change the appearance, size, and color of a form by using the Properties window. You can use the Form class members to set properties or override event handler methods at runtime. The Form class contains properties and methods too numerous to completely itemize. Among the interesting ones are the following:

  • ControlBox. A Boolean property that toggles the visibility of the minimize, maximize, and close buttons on the caption bar. The default value, true, displays the buttons. The buttons can be set individually, but only as to their being enabled or disabled.
  • KeyPreview. A Boolean property that permits a form to intercept all keystrokes prior to the control that has focus. To implement this property, either a KeyPress, a KeyDown, or a KeyUp event handler must also be attached to the form. To prevent a text box from receiving the event, set the KeyXXXEventArgs.Handled property to true.
  • ShowInTaskbar. A property that shows a window's caption bar text in the taskbar when set to true. The default value is true.
  • WndProc. The .Net version of the Win32 default window procedure. The WndProc method has a Message structure as a parameter and returns void. A window procedure handles operating system notifications that an action, such as a mouse move, has taken place. Each window message, or notification, has a default behavior that is applied by the default window procedure if no action is taken by any of the previously called procedures in the window chain.

Table 9.6 describes some other members of the Form class.

Table 9.6: Form Class Members

table-9.6.gif

Using the properties and methods of the Form class you can alter the appearance of the form. The given examples contains some samples that can change the appearance and functionality of the form.

Examples of Changing the appearance of the form


    // Set the font of the form.

    Form1.Font = New System.Drawing.Font("Verdana", 10, System.Drawing.FontStyle.Bold)

    // Make the Form transparent.
    Form1.Opacity = 0.5

    // Make the Form topmost.
    Form1.TopMost = True

    // Set the title bar text of the form.
    form1.Text = "My Dialog Box";

    // Display a help button on the form.
    Form1.HelpButton = True

    // Define the border style of the form to that of a dialog box.

    Form1.FormBorderStyle = FormBorderStyle.FixedDialog

    // Set the MaximizeBox to false to remove the maximize box.

    Form1.MaximizeBox = False

    // Display the form as a modal dialog box.
    Form1.ShowDialog()

Conclusion

Hope this article would have helped you in understanding the Form Class using VB.NET.

 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.