Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

How to exit from a Login Form in a Windows Forms application without closing the application

How to exit from a Login Form in a Windows Forms application without closing the application

Problem:

Customer is developing a Windows Forms application and would like it to display a LoginForm to do user authentication and then to exit the application if it fails or continue on and display the main form if successful.

How can this be done?

Resolution:

Change the main.cbl program to display the loginform first and then start the application with the main form depending on the results of the login.

Example:

main.cbl

       class-id winformlogin.Main.
       method-id Main static
           attribute System.STAThread.
       local-storage section.
       01 mainForm type winformlogin.Form1.
       01 loginForm type winformlogin.LoginForm1.
       01 myresult  type DialogResult.
       procedure division.
       
           set loginForm to new winformlogin.LoginForm1
           set myresult to loginForm::ShowDialog
           if myresult = type DialogResult::OK
              set mainForm to new winformlogin.Form1()
              invoke type System.Windows.Forms.Application::EnableVisualStyles()
              invoke type System.Windows.Forms.Application::Run(mainForm)
           else
              invoke type System.Windows.Forms.Application::Exit
           end-if
           goback.
       
       end method.
       end class.

LoginForm1.cbl

       class-id winformlogin.LoginForm1 is partial
                 inherits type System.Windows.Forms.Form.

       working-storage section.
 
       method-id NEW.
       procedure division.
           invoke self::InitializeComponent()
           goback.
       end method.

       method-id btnOK_Click final private.
       procedure division using by value sender as object 
                                         e as type System.EventArgs.
           set self::DialogResult to type DialogResult::OK
           invoke self::Close()
           goback.
       end method.

       method-id btnCancel_Click final private.
       procedure division using by value sender as object
                                         e as type System.EventArgs.
           set self::DialogResult to type DialogResult::Cancel
           invoke self::Close()
           goback.
       end method.

       end class.

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-10-25 17:27
Updated by:
 
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.