Created On:  20 July 2012


Can I display a graphical Message Box in a Visual COBOL console application or some other non-Forms based project type?

An error message appears about class not being found.


You can use the MessageBox class in a console application but you will have to add the proper assembly to the project.

In the Visual COBOL Help search for MessageBox.  The Help will list a number of items because there are a couple different MessageBox classes depending on the technology you are using such as Windows Forms or WPF.

Assuming you are using Windows Forms, click on the entry for MessageBox Class in System.Windows.Forms.

The docs will tell you that the assembly name where this class resides is called System.Windows.Forms.

In Solution Explorer, right click on References under the project name in which you wish to display the message and then select Add Reference.
From the .NET tab scroll to find System.Windows.Forms for the .NET Framework version that you are using.
This will be .NET Framework 4 by default.

Click on OK to add the assembly to the project.

In order to be able to reference this class without fully qualifying the name like System.Windows.Forms.MessageBox you will need to add the namespace to the project or to the program.

To add it to the project, open up project properties by double clicking on Properties under the project name and then navigate to the Namespace tab.
Scroll down the list and check System.Windows.Forms and save.

If you wish to add the namespace to just that program then add the directive:

      $set ilusing"System.Windows.Forms" to the top of the program.

Example: this is a console program that displays a messagebox.

     $set ilusing"System.Windows.Forms"
      program-id. Program1 as "testpopup.Program1".
      procedure division.
          invoke type MessageBox::Show("This is a message")