Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello,

I am getting problem during form hide and show, problem is:- when windows state property set on normal so,my both form opened, when we set property is Maximized so, code is correct running, only one form show.

please help me.

Thanks in Advance.

Regards
Ankit Agarwal
Software Engineer
Posted
Updated 2-Jun-14 4:31am
Comments
phil.o 2-Jun-14 5:25am    
If one of the form is maximized, then it means it will occupy the whole screen.
Then how could the second form be visible?
[no name] 2-Jun-14 5:30am    
I can see a instance of second form, when opened in maximized mode.
Karthik_Mahalingam 2-Jun-14 5:49am    
please add more info to the question.
not clear.
[no name] 2-Jun-14 6:17am    
Hi Karthik Ankit Here,
Actually Two forms in my application and both form size is same WindowsState is normal, I want to hide first form before open second form,
Both forms are displayed,
If First size is Maximized do, Only Second form show.
ZurdoDev 2-Jun-14 11:32am    
1. Reply to the comment so that the user is notified.
2. It is not real clear what you want.

1 solution

What phil.o and Wes Aday stated is true - the behavior you witness is expected.

However, if you limit the size of each form, then you can control how much of the desktop landscape the forms will occupy when they are maximized. One way you achieve this is by overriding the OnSizeChanged event handler. The following application demonstrates this solution.
C#
using System;
using System.Windows.Forms;

namespace MaximizeWindowOverride
    {

    public partial class Form1 : Form
        {

        // ******************************************* class constants

        const int       MAXIMUM_HEIGHT = 500;
        const int       MAXIMUM_WIDTH = 600;

        // ******************************************* class variables

        FormWindowState current_window_state;

        // ***************************************************** Form1

        public Form1 ( )
            {

            InitializeComponent ( );

            current_window_state = this.WindowState;
            }

        // ********************************************* OnSizeChanged
        
        protected override void OnSizeChanged ( EventArgs e )
            {

            base.OnSizeChanged ( e );

            if ( ( this.WindowState == FormWindowState.Maximized ) &&
                 ( current_window_state != FormWindowState.Maximized ) )
                {
                this.Width = MAXIMUM_WIDTH;
                this.Height = MAXIMUM_HEIGHT;

                this.WindowState = FormWindowState.Normal;
                }

            current_window_state = this.WindowState;
            }

        } // class Form1

    } // namespace MaximizeWindowOverride

Hope that helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900