简体   繁体   中英

Can't restore minimized WinForms app from taskbar

I have a very strange problem, in which a standard WinForms C# application can sometimes not be restored from the taskbar, after it has been minimized or if another application was used in maximized mode.

This happens on Windows Server 2012 and on Windows 10 (I haven't tested it in other OS'es). If the mouse hovers over my applications taskbar icon, a thumbnail view of my application shows up. Moving the mouse cursor up, to hover over the thumbnail, the application actually shows up on the desktop again, but if I left click on the thumbnail or moves the cursor off the thumbnail, it disappears again. If instead I right click the thumbnail, I can choose "Maximize" or "Restore" from the popup menu, and either works as expected. So the issue only affects regular left clicking on the taskbar icon or the popup thumbnail.

I'm using .NET Framework 4.6 for my application, and the application consists only of a single form with default property values and no WndProc overrides or other fancy things.

I have no idea how to debug this, and the bug is not reproducible 100% of the times, so any suggestions on how I can capture and provide more information to help solve the issue would be very welcome.

For me, the problem was an always visible modeless Form that was owned by the main window. Apparently when the main window is minimized, the modeless form needs to be minimized as well. WinForms doesn't do this automatically for you. I had to subscribe to the main window Resize event, and set the state in there:

private void MainWindow_OnResize(object sender, EventArgs e)
{
    modelessForm.WindowState = WindowState;
}

This issue was not encountered on Windows 7, only on Windows 10.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM