Share via


Preparing the Windows Form in Visual Studio

Traditional Visual Basic 6 Windows applications typically defined a default form under the name Form1. In keeping with that pattern in a Windows project, you use the same default form name, Form1 with a .cs or .vb extension that depends on the language you use.

  1. If Form1 is not already displayed in the main window, double-click Form1 in Solution Explorer.
Form1 opens in the Designer.
  1. From the View menu, click Code.
The code view of the Form1 class appears. The display of this class depends on whether your Windows application is coded in Visual Basic or C\#.

In C\#, the Form1 class displays the following:

  - The class signature.
  - A constructor (Form1).

In Visual Basic, the Form1 class displays the following:

  - The class signature (a Form1 class).

    > [!NOTE]
    > <P>Additional methods and variables of the Form1 class are contained in a separate "partial" class. (This is true for both C# and Visual Basic.) Partial classes are explained later in Windows Project Setup.</P>

Next, you add a private helper method that is used as the designated location for all the code that configures Crystal Reports for the class.

To add a private helper method for Crystal Reports configuration code

  1. Add to this Form1 class a new private scope helper method with no return value, named ConfigureCrystalReports().

    Private Sub ConfigureCrystalReports()
    
    End Sub
    
    private void ConfigureCrystalReports()
    {
    }
    

    Next you add a Form_Load event handler, and then put a call to ConfigureCrystalReports() within the Form_Load event handler. This will cause the ConfigureCrystalReports() method to run automatically when the form loads.

  2. From the View menu, click Designer.

  3. Double-click on Form1.

    You are returned to Code view. Because you double-clicked on Form1, a Form1_Load event handler is automatically generated in the Form1 class.

  4. Within the Form1_Load event handler, enter a call to the ConfigureCrystalReports() method.

    ConfigureCrystalReports()
    
    ConfigureCrystalReports();
    
  5. From the File menu, click Save All.