2
votes

I have a Winforms application, which I'm able to minimize by clicking on the corresponding button on the top right of the window; I can then maximize it by clicking on this application's taskbar icon.

My problem is that if the window is maximized, it should be minimized when I click on the taskbar icon again, and it's currently not happening.

How can I make this behavior happen? I don't want to have to use NotifyIcon or system tray.

3
What? You say you can do those things, but you want code to do it? This question is very unclear, shows no research and is far too broad.crthompson
@paqo I think you're being quite harsh on that question. The intent itself is clear: performing minimization and maximization from the application's taskbar tab. The research, even though not pointed out clearly, is here: he talks about NotifyIcon and system tray.Kilazur
I mean to say I can only once maximize windows form from taskbar followed by mininimize button click on windows form. After that I can not minimize it from taskbar. I can minimize it from windows form button click but not from taskbarShailesh Jaiswal
I created the minimal WinForms app with VS2013, and under Win81 the right-click context menu on the taskbar does not include Minimise, Maximise or Restore, but clicking the taskbar icon performs these actions as expected (restore when currently minimised, otherwise minimise). On your own system, perform this experiment to determine whether there is something odd about the test environment or whether you have somehow messed things up in your app.Peter Wone

3 Answers

6
votes
const int WS_MINIMIZEBOX = 0x20000;
const int CS_DBLCLKS = 0x8;
protected override CreateParams CreateParams
{
    get
    {
        CreateParams cp = base.CreateParams;
        cp.Style |= WS_MINIMIZEBOX;
        cp.ClassStyle |= CS_DBLCLKS;
        return cp;
    }
}
0
votes

You can do it with no borders too.. requires additional coding

-1
votes

Try to check what's going on in LocationChanged, Move, RegionChanged, Resize, ResizeBegin, ResizeEnd, SizeChanged events. Could be that some code in any of these events is blocking the behavior you described.

I am not seeing the described problem on a new empty form.

Update: I am using Window 7 Pro.