Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi frnds...

I want to launch the application in the maximized form when use select maximized button and then minimize the application, and then close..

My code is... In Form Closing event..

C#
if (this.WindowState == FormWindowState.Minimized)
                {
                    Properties.Settings.Default.MyState = FormWindowState.Normal;
                }
                else
                {
                    Properties.Settings.Default.MyState = this.WindowState;
                }
                if (this.WindowState == FormWindowState.Normal)
                {
                    Properties.Settings.Default.MySize = this.Size;
                    Properties.Settings.Default.MyLoc = this.Location;
                }
                else
                {
                    Properties.Settings.Default.MySize = this.RestoreBounds.Size;
                    Properties.Settings.Default.MyLoc = this.RestoreBounds.Location;
                }
                Properties.Settings.Default.Save();


Now it is launching in the normal state only..


Please anybody help me...
Posted

You should put some code like this in your Form's Load event
C#
this.WindowState = Properties.Settings.Default.MyState;
 
Share this answer
 
I am not really sure if I understood your problem. Let me try though:

1. First time the form should open maximized (This can be done using window state property).
2. After that every time the form should be opened as it was at the time of closing. If it was minimized, open normally. (Right?)

You will need to save the location and size of the form which you are already doing. But are you assigning the value to appropriate properties next time the form is opened? This should be done before Load event.

Edit: Handle the StateChanged event for the for the form and save the settings that tell that the form was maximized. In the form closing check the state again and update setting if needed. Following should help:

StateChangedEventHandler Begin

If WindowState is Maximized then

OpenMaximizedNextTimeSetting = true

End

End

FormClosingEventHandler Begin

If OpenMaximizedNextTimeSetting is true and (WindowState is not minimized OR WindowState is not maximized) then

OpenMaximizedNextTimeSetting = false

End

End


HTH
 
Share this answer
 
v3
Comments
Harish Reddy K 18-Jul-11 6:26am    
No.. not like that...

First I launch the application in Normal State.. if user maximizes the application once and then he minimizes it.. after then he closed the application in minimized state..

At that time i want to launch the application in Maximized state only..

If Client closed in normal state then in relaunch the client starts in normal state only..

any way thanks for ur reply..

Regards
Harish Reddy
dan!sh 19-Jul-11 2:12am    
Upddated the reply. See if it helps.
And are you reading these settings back, and applying them when you open the form?

BTW: You don't need to keep on using this. - it is implied in all non-static methods. Save it until you need it to sort out name conflicts.
 
Share this answer
 
Comments
Harish Reddy K 18-Jul-11 6:31am    
ya... i'm reading in the form load event...
OriginalGriff 18-Jul-11 6:33am    
Post the code - we need to know how you are handling both parts!
Harish Reddy K 18-Jul-11 6:39am    
In Form Closing Event...


if (this.WindowState == FormWindowState.Minimized)
{
Properties.Settings.Default.MyState = FormWindowState.Normal;
}
else if (this.WindowState == FormWindowState.Normal)
{
Properties.Settings.Default.MySize = this.Size;
Properties.Settings.Default.MyLoc = this.Location;
}
else if (this.WindowState == FormWindowState.Maximized)
{
Properties.Settings.Default.MySize = this.RestoreBounds.Size;
Properties.Settings.Default.MyLoc = this.RestoreBounds.Location;
}

Properties.Settings.Default.Save();


In Form Load Event...

this.Size = Properties.Settings.Default.MySize;
this.Location = Properties.Settings.Default.MyLoc;
this.WindowState = Properties.Settings.Default.MyState;
I'm not sure your requirements are clear. Let's assume you need to keep the form either maximized or minimized, never of custom or default size. It that true. If so, do the following:

1) In the form's constructor or in the properties of the form, specify FormWindowState.Maximized.

2) After the form is shown for the first time, remember the actual size and position of the Form. Set FormWindowState.Normal by apply the size and position the same as for maximized. Do you know how maximized works? It is exact same form state as normal, only the form shifted in negative X and Y to hide borders with appropriate size.

3) Makes the Form non-resizeable.

—SA
 
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