Absent Member.
Absent Member.
1176 views

LoginForm Call MdiForm

Jump to solution

Hi, how to close a LoginForm passing control to MDIForm without closing the application?

0 Likes
1 Solution

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

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.

View solution in original post

0 Likes
2 Replies
Micro Focus Expert
Micro Focus Expert

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.

View solution in original post

0 Likes
Absent Member.
Absent Member.

Thanks Chris. Perfect! Thank you very much

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.