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 make the main form in a WPF application invisible after showing a new form

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

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 

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-05-30 11:13
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.