LoginForm Call MdiForm

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

  • Verified Answer

    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.