.netCoders Contact Us
Search:

Windows Forms

When you create a Windows application, you're likely to have at least one form. There are many different properties you can set to determine the UI and behavior of your form, far too many to cover here. In addition to reading this page, we also suggest creating a windows form project, and going down the list of properties in the Visual Studio.NET Properties window for the form.

Windows Style

Fixed vs. Dynamically Sizable
The first decision you'll need to make is whether your form is designed for a specific size (eg. a dialog box), or can support resizing (eg. the main application form). If a user can resize a form, the form should also support Maximizing and Minimizing. Here are the properties involved in sizing your forms, and controlling whether the user can resize the form.

Property Description
MaximizeBox Indicates whether the form has a maximize button in the upper-right corner of the caption bar
MinimizeBox Indicates whether the form has a minimize button in the upper-right corner of the caption bar
Size Indicates the size of the form, in pixels
MaximumSize Indicates the maximum size of the form, in pixels. This is used if a form is resizable, but shouldn't be resized larger than the indicated size.
MinimumSize Indicates the minimum size of the form, in pixels. This is used if a form is resizable, but shouldn't be resized smaller than the indicated size.
FormBorderStyle An enumeration controlling the border of the form, and what buttons can show up in the caption bar. A Fixed style indicates the form is not resizable, whereas a Sizable style indicates it is resizable.

Form Inheritance

Form inheritance allows you to create a base class form, and create derived classes that inherit the properties and UI of the parent form. Using form inheritance, for example, you can create a template form that contains all the common navigation elements and properties, such as a caption, menu bar, and status bar. You then can create multiple forms derived from this template, and they will all have the caption, menu bar, and status bar.

Creating the base form is just like creating any other form. You open up Visual Studio.NET, and create a form using the Forms Designer. Next, create a blank form for a derived class. In the code-behind, indicate that the form inherits from the base form by using the following syntax:

' Visual Basic
Public Class Form2
    Inherits Namespace1.Form1

// C#
public class Form2 : Namespace1.Form1