IgnaceMaes / MaterialSkin

Theming .NET WinForms, C# or VB.Net, to Google's Material Design Principles.
MIT License
2.84k stars 831 forks source link

Taskbar disappeared when set WindowState to Maximized. #96

Open wk-j opened 8 years ago

wk-j commented 8 years ago

In MaterialForm if set WindowsState to Maximized (in Properties Windows) form will display as fullscreen.

Problem

I'm try to fix with this code but restore button still not working.

        private void Form_Load(object sender, EventArgs e)
        {
            MaximizeWindow(true);
        }
        /*
            Fix Full Screen
        */
        private Size previousSize;
        private Point previousLocation;
        private const int MONITOR_DEFAULTTONEAREST = 2;

        private void MaximizeWindow(bool maximize)
        {
            if (maximize)
            {
                IntPtr monitorHandle = MonitorFromWindow(Handle, MONITOR_DEFAULTTONEAREST);
                MONITORINFOEX monitorInfo = new MONITORINFOEX();
                GetMonitorInfo(new HandleRef(null, monitorHandle), monitorInfo);
                previousSize = Size;
                previousLocation = Location;
                Size = new Size(monitorInfo.rcWork.Width(), monitorInfo.rcWork.Height());
                Location = new Point(monitorInfo.rcMonitor.left, monitorInfo.rcMonitor.top);
            }
            else
            {
                Size = previousSize;
                Location = previousLocation;
            }
        }