static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //For some reason the glow has to be initialized outside of the parent form TestForm form = new TestForm(); MetroFormGlow glow = new MetroFormGlow(form); form.glow = glow; glow.Show(); Application.Run(form); }
protected override void WndProc(ref Message m) { if (m.Msg == WinAPI.WM_NCHITTEST) { Point mouse = this.PointToClient(Cursor.Position); //System.Diagnostics.Debug.WriteLine(mouse.X + ":" + mouse.Y); UpdateCaptionControl(0, (btnClose.Contains(mouse) ? 1 : 0)); UpdateCaptionControl(1, (btnMaximize.Contains(mouse) ? 1 : 0)); UpdateCaptionControl(2, (btnMinimize.Contains(mouse) ? 1 : 0)); foreach (int b in capcontrols) { if (b != 0) { m.Result = (IntPtr)WinAPI.HTBORDER; return; } } bool left = false, right = false, top = false, bottom = false; if (mouse.X <= bordersize) { left = true; } else if (mouse.X >= this.Width - bordersize) { right = true; } if (mouse.Y <= bordersize) { top = true; } else if (mouse.Y >= this.Height - bordersize) { bottom = true; } if (top && left) { m.Result = (IntPtr)WinAPI.HTTOPLEFT; } else if (top && right) { m.Result = (IntPtr)WinAPI.HTTOPRIGHT; } else if (bottom && left) { m.Result = (IntPtr)WinAPI.HTBOTTOMLEFT; } else if (bottom && right) { m.Result = (IntPtr)WinAPI.HTBOTTOMRIGHT; } else if (top) { m.Result = (IntPtr)WinAPI.HTTOP; } else if (bottom) { m.Result = (IntPtr)WinAPI.HTBOTTOM; } else if (left) { m.Result = (IntPtr)WinAPI.HTLEFT; } else if (right) { m.Result = (IntPtr)WinAPI.HTRIGHT; } else if (CaptionDragBounds.Contains(mouse)) { m.Result = (IntPtr)WinAPI.HTCAPTION; } else if (CaptionBounds.Contains(mouse)) { m.Result = (IntPtr)WinAPI.HTBORDER; } else { m.Result = (IntPtr)WinAPI.HTCLIENT; } return; } else if (m.Msg == WinAPI.WM_NCMOUSELEAVE) { for (int i = 0; i < capcontrols.Length; i++) { capcontrols[i] = 0; } this.Invalidate(); } else if (m.Msg == WinAPI.WM_NCLBUTTONUP) { Point mouse = this.PointToClient(Cursor.Position); if (btnClose.Contains(mouse) && capcontrols[0] == 2) { this.Close(); return; } else if (btnMaximize.Contains(mouse) && capcontrols[1] == 2) { this.WindowState = (this.WindowState == FormWindowState.Maximized ? FormWindowState.Normal : FormWindowState.Maximized); if (this.WindowState == FormWindowState.Maximized) { glow.Hide(); } else { glow.Show(); } return; } else if (btnMinimize.Contains(mouse) && capcontrols[2] == 2) { this.WindowState = FormWindowState.Minimized; return; } for (int i = 0; i < capcontrols.Length; i++) { if (capcontrols[i] == 2) { capcontrols[i] = 1; } } this.Invalidate(); } else if (m.Msg == WinAPI.WM_NCLBUTTONDOWN) { Point mouse = this.PointToClient(Cursor.Position); UpdateCaptionControl(0, (btnClose.Contains(mouse) ? 2 : 0)); UpdateCaptionControl(1, (btnMaximize.Contains(mouse) ? 2 : 0)); UpdateCaptionControl(2, (btnMinimize.Contains(mouse) ? 2 : 0)); } else if (m.Msg == WinAPI.WM_NCCALCSIZE && m.WParam.ToInt32() == 1) { m.Result = new IntPtr(0x00); return; } else if (m.Msg == WinAPI.WM_SYSCOMMAND) { int command = m.WParam.ToInt32() & 0xFFF0; if (command == WinAPI.SC_MINIMIZE) { glow.WindowState = FormWindowState.Minimized; } else if (command == WinAPI.SC_RESTORE) { glow.WindowState = FormWindowState.Normal; } } else if (m.Msg == WinAPI.WM_ACTIVATE) { if (m.WParam.ToInt32() == 0) { glow.Hide(); } else { if (this.WindowState != FormWindowState.Maximized) { glow.Show(); glow.Render(); //glow.BringToFront(); this.BringToFront(); } } } base.WndProc(ref m); }