When I minimize my application I hide the form and make a notifyicon visible. When I double click the notifyicon I want the application to return to its original size. I am not sure how to catch what the WindowState was before minimize was clicked.
I am using the code below to handle the double click but I am unsure how to set the WindowState. If I don't set the WindowState the form does not regain focus and just stays in the taskbar and the notifyicon also remains in the system tray.
If you want to know what was the last window state you retain it in a private FormWindowState enum.
Bogdan
If someone helped you then please Rate his post and mark the thread as Resolved
Please improve your messages appearance by using tags[ code] Place your code here [ /code]
window state is either maximized or normal. if it was maximized before it was minimized, then setting it to normal should restore it to its last position.
Thanks for all your replies but it does not seem to be working for me.
When I restore using "this.WindowState = FormWindowState.Normal;" the window always goes to interim size regardless of the size before it was minimized. Weird ...
If I don't use the notifyicon in the system tray and just leave it in the taskbar it works fine so it seems my notifyicon is causing this problem.
Can you please post the code for how are you catching MINIMIZE event and what are you doing in that event handler. Also code of NotifyIcon double click event handler.
First override WndProc function and check for NON CLIENT AREA BUTTON DOWN(i.e WM_NCLBUTTONDOWN) message and check whether mouse down position was indeed on MINBUTTON.
Add FormWindowState variable to keep track of previous WindowState. Also you need to declare two more constant values which are WIN32 defines for WM_NCLBUTTONDOWN and HTMINBUTTON messages.
Code:
const int WM_NCLBUTTONDOWN = 0x00A1;
const int HTMINBUTTON = 8;
In notifyicon double click event assign previously stored WindowState value to current WindowState.
If we had WindowStateChanged event then we could have avoided all these things.
window state is either maximized or normal. if it was maximized before it was minimized, then setting it to normal should restore it to its last position.
As MadHatter said this is true in .NET Framework 1.1. But in 2.0 they have distinguished between NORMAL and MAXIMIZED.
In the Form1 constructor you are setting the state to Maximized. In notifyIcon1_MouseDoubleClick you are setting the state to Normal. These are not the same thing, so you wouldn't get the same result. Normal is the last non-maximized, non-minimized size, or the designer size.
open notepad. maximize it, click the minimize button, then from the task bar, select restore. see what happens. it goes back to the last way it was. this is the same thing that happens by setting the window state w/ normal after its been minimized. but IMO naveen's solution is the one I'd do.
open notepad. maximize it, click the minimize button, then from the task bar, select restore. see what happens. it goes back to the last way it was. this is the same thing that happens by setting the window state w/ normal after its been minimized. but IMO naveen's solution is the one I'd do.
Naveen's method works perfectly - thanks again Naveen.
Just out of interest, MadHatter, notepad does what I want my app to do. Do you think using normal should do what I want? I thought normal was the last state before it was minimized but it just does not seem to work. zips description seems to make sense but it is strange their is no easier way to do this apparently simple task.
Actually, it makes perfectly good sense: Maximize has no need for size values, and Minimize has no need for size values. Only Normal would use size values, so only the size from the last Normal state is stored.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.