How to make the main form in a WPF application invisible after showing a new form

0 Likes

Problem:

Customer has a Windows Presentation Foundation (WPF) application written in Visual COBOL that displays a main form and then depending on options selected will display various other forms.

When a new form is displayed they would like to make the main form invisible so that the user cannot click on it and it is not covering up the other icons on the desktop.

When the sub forms exit they would like control to return to the main form and make it visible once again.

How can this be accomplished?

Resolution:

This can be accomplished by using the Visibility property of the main form.

Please download the example .zip file and unzip it to your C:\ drive.

Here is the source code for the main form program and the sub form program:

       class-id invisibleformWPF.Window1 is partial
                 inherits type System.Windows.Window.
       working-storage section.
       01 myform2 type invisibleformWPF.form2.
       method-id NEW.
       procedure division.
           invoke self::InitializeComponent()
           goback.
       end method.

       method-id button1_Click final private.
       procedure division using by value sender as object e as type System.Windows.RoutedEventArgs.
           set myform2 to new invisibleformWPF.form2
           set self::Visibility to type Visibility::Hidden
           invoke myform2::ShowDialog
           set self::Visibility to type Visibility::Visible
       end method.
       end class.

       class-id invisibleformWPF.form2 is partial
                 inherits type System.Windows.Window.
       working-storage section.
       method-id NEW.
       procedure division.
           invoke self::InitializeComponent()
           goback.
       end method.

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

1541.invisibleformWPF.zip 

Comment List
Related
Recommended