Created On:  20 April 2011

Problem:

How does one handle the processing of more than one form in a .NET Windows Forms application in Visual COBOL?  How do I create the forms, show the forms, hide the forms etc.?

Resolution:

In a .NET WinForm application, a form is simply an instance of the System.Windows.Forms.Form class so it may be manipulated like any other .NET object.

When you first create a Windows Form Application a main form named Form1 is automatically added to the project and it is instantiated in the main.cbl program which is the entry point of the project.

Other forms can be added by right clicking on the project name in Solution Explorer add selecting Add->New item->Windows Form.
You can then instantiate and manipulate these new forms from your main form.

Please download the attachment MultiFormDemo.zip from this article and unzip it onto your C:\drive retaining the folder structure in the .zip file.

Using Visual COBOL open up the solution C:\MultiFormDemo\MultiFormDemo\MultiFormDemo.sln.
Press F5 to run the demo.
-----------------------------------------
Here is the Readme file for the demo:


MultiForms Demo

This example demonstrates how multiple Windows forms can be used within a .NET WinForm application.
The main form Form1 is created in main.cbl. Form1 contains a number of button controls which allow you to create two additional forms called Form2 and Form3. Once these forms are created you can click additional buttons to control whether they sould be hidden or shown.

An event handler is added to Form1 in order to capture the FormClosed event for both Form2 and Form3 so that Form1 can enable and disable the correct buttons to allow for a new instance of Form2 or Form3 to be created. The FormClose event is triggered by clicking on the Close Form button on Form2 or Form3.