Highlighted
Absent Member.
Absent Member.
4559 views

2 or More WFA on Visual Cobol

Jump to solution

[Migrated content. Thread originally posted on 19 April 2011]

How I can move from one windows form to another with Visual Cobol?. And how I can create those on my project and I can Hide and Un-Hide?. Please let me know where I can find one example. My email is: jose61@pryma.ws
0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: 2 or More WFA on Visual Cobol

Jump to solution

For anyone else that would like to get a copy of this demo, I have made it available in the articles section of this Community web site.

How to handle multiple forms in a .NET Windows Forms Application

View solution in original post

0 Likes
11 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: 2 or More WFA on Visual Cobol

Jump to solution
I have created a full example that I will e-mail to you.
The code for the main form is shown below:

Let me know if you need anything else.


      *-------------------------------------------------------------------------*
      *                        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 should 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.                                              *
      *-------------------------------------------------------------------------*
       class-id MultiFormsDemo.Form1 is partial
                 inherits type System.Windows.Forms.Form.
       
       working-storage section.
       01 Form2    type MultiFormsDemo.Form2.
       01 Form3    type MultiFormsDemo.Form3.
       method-id NEW.
       procedure division.
           invoke self::InitializeComponent
           goback.
       end method.

       method-id btnCreate2_Click final private.
       procedure division using by value sender as object e as type System.EventArgs.
           set Form2 to new type MultiFormsDemo.Form2
           
      *>  The following adds an event handler to this form which will catch the FormClosed event on Form2     
           invoke Form2::add_FormClosed(new System.Windows.Forms.FormClosedEventHandler(self::Form2_Closed))
           invoke Form2::Show
      *>  Disable the Create Form2 button so only one instance of Form2 will be created.     
           set self::btnCreate2::Enabled to false
           set self::btnHide2::Enabled to true
           set self::btnShow2::Enabled to true
       end method.

       method-id btnCreate3_Click final private.
       procedure division using by value sender as object e as type System.EventArgs.
           set Form3 to new type MultiFormsDemo.Form3
           
      *>  The following adds an event handler to this form which will catch the FormClosed event on Form3     
           invoke Form3::add_FormClosed(new System.Windows.Forms.FormClosedEventHandler(self::Form3_Closed))
           invoke Form3::Show
      *>  Disable the Create Form3 button so only one instance of Form3 will be created.         
           set self::btnCreate3::Enabled to false
           set self::btnHide3::Enabled to true
           set self::btnShow3::Enabled to true
       end method.

       method-id btnHide2_Click final private.
       procedure division using by value sender as object e as type System.EventArgs.
           invoke Form2::Hide
       end method.

       method-id btnHide3_Click final private.
       procedure division using by value sender as object e as type System.EventArgs.
           invoke Form3::Hide
       end method.

       method-id btnShow2_Click final private.
       procedure division using by value sender as object e as type System.EventArgs.
           invoke Form2::Show
       end method.

       method-id btnShow3_Click final private.
       procedure division using by value sender as object e as type System.EventArgs.
           invoke Form3::Show
       end method.

       method-id Form1_Load final private.
       procedure division using by value sender as object e as type System.EventArgs.
      *> set the initial state of the buttons.
           set self::btnCreate2::Enabled to true
           set self::btnHide2::Enabled to false
           set self::btnShow2::Enabled to false
           
           set self::btnCreate3::Enabled to true
           set self::btnHide3::Enabled to false
           set self::btnShow3::Enabled to false
                 
       end method.
      *> The following event handler will be triggered when the Close Form2 button is clicked in Form2
       method-id Form2_Closed.
       procedure division using by value sender as object e as type System.Windows.Forms.FormClosedEventArgs.
           set self::btnCreate2::Enabled to true
           set self::btnHide2::Enabled to false
           set self::btnShow2::Enabled to false
       end method.
      *> The following event handler will be triggered when the Close Form3 button is clicked in Form3
       method-id Form3_Closed.
       procedure division using by value sender as object e as type System.Windows.Forms.FormClosedEventArgs.
           set self::btnCreate3::Enabled to true
           set self::btnHide3::Enabled to false
           set self::btnShow3::Enabled to false
       end method.

       method-id button1_Click final private.
       procedure division using by value sender as object e as type System.EventArgs.
          invoke self::Close
       end method.

       end class.

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: 2 or More WFA on Visual Cobol

Jump to solution

For anyone else that would like to get a copy of this demo, I have made it available in the articles section of this Community web site.

How to handle multiple forms in a .NET Windows Forms Application

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: 2 or More WFA on Visual Cobol

Jump to solution
Thanks Chris,
That works, but now how I can Hide de first, when I open the second?
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: 2 or More WFA on Visual Cobol

Jump to solution
In this demo form1 is meant to be the control program that is always running and handles the creation of the other forms.

This form can be hidden by issuing:

invoke self::Hide

after the invoke Form2::Show is issued.

The form will still be active however, it just will not be displayed.
It can be reactivated by doing an invoke self::Show on it.

If you wish for Form2 to replace Form1 as the main program then the control program should not be Form1 it should be in main.cbl.

Maybe if you can give me some more details on how you wish your application to work then I can give you an example that more closely resembles what you are trying to accomplish?

Thanks.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: 2 or More WFA on Visual Cobol

Jump to solution
I have one form1 to Login and de the second is my aplication. I have to Hide my form1 when the after of before user has been login. And my aplication has one menu, each option has a corresponding form, when this corresponfig form is show, de second has to be hide or put in modal 0.
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: 2 or More WFA on Visual Cobol

Jump to solution
Hi,

I have e-mailed you another example program which uses multiple forms in a Windows Forms application.

This is really a .zip file but I had to rename it in order for our e-mail provider to allow it as an attachment.
Rename the .doc to .zip when you download it.

This one uses an ApplicationContext class to control the displaying of multiple forms in an application.
I modified the main.cbl to invoke the Application::Run method to use the ApplicationContext instance instead of displaying a form automatically.

The ApplicationContext class creates event handlers for the closing of the other forms so it knows when to close the application.

Demo now does the following:

1. Displays the LoginForm
2. If Login is OK it closes LoginForm and displays Form1
3. Form1 has a menu. If Test menu item selected TestForm will be displayed as Modal.
4. Exiting TestForm will return to Form1
5. When Form1 is closed Application will exit.

There are many different ways to accomplish this same thing, this is only one example.

You should read up on the System.Windows.Forms class and System.Windows.Forms.Application class for more information and examples of how to work with Windows Forms applications.

Let me know if you have any questions.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: 2 or More WFA on Visual Cobol

Jump to solution
Thanks Chris
I'd downloaded this demo and aplied this to my aplication and works. I did another post, how add items to ComboBox.

Sincerely

Manuel.
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: 2 or More WFA on Visual Cobol

Jump to solution
Excellent, I sent you a new sample for the combobox binding and replied on the other post.
0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

RE: 2 or More WFA on Visual Cobol

Jump to solution

When I click on the link, it says the webpage no longer exists.

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: 2 or More WFA on Visual Cobol

Jump to solution

Hello Austin1,

Please try the following link.

Blair McDonald

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

RE: 2 or More WFA on Visual Cobol

Jump to solution

Thanks!

Austin

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.