Last active
May 21, 2022 22:19
-
-
Save colhountech/ef952fd54c55a3fe330a8d46fc391995 to your computer and use it in GitHub Desktop.
AcrylicUI Window No Border Hack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region Window, No Border Hacks | |
protected override void WndProc(ref Message message) | |
{ | |
// Resize Window | |
if (message.Msg == WinUserH.WM_NCHITTEST) | |
{ | |
base.WndProc(ref message); | |
if (this.WindowState == FormWindowState.Normal) | |
{ | |
if ((int)message.Result == WinUserH.HT_CLIENT) | |
{ | |
var cursor = this.PointToClient(Cursor.Position); | |
WindowPanel.CheckResizeClientAreaHit(this.ClientSize, ref message, cursor); | |
} | |
} | |
return; | |
} | |
// Remove border and keep snap window | |
if (message.Msg == WinUserH.WM_NCCALCSIZE && message.WParam.ToInt32() == 1) | |
{ | |
return; | |
} | |
// Keep form size when it is minimized and restored. | |
if (message.Msg == WinUserH.WM_SYSCOMMAND) | |
{ | |
int wParam = (message.WParam.ToInt32() & 0xFFF0); | |
if (wParam == WinUserH.SC_MINIMIZE) | |
{ | |
//save client size | |
_restoreSize = this.ClientSize; | |
} | |
if (wParam == WinUserH.SC_RESTORE) | |
{ | |
// restore client size | |
this.Size = _restoreSize; | |
} | |
} | |
base.WndProc(ref message); | |
} | |
protected override void OnPaintBackground(PaintEventArgs e) | |
{ | |
base.OnPaintBackground(e); | |
if (!_flatBorder) | |
return; | |
/* var g = e.Graphics; | |
using (var p = new Pen(Colors.DarkBorder)) | |
{ | |
var modRect = new Rectangle(ClientRectangle.Location, new Size(ClientRectangle.Width - 1, ClientRectangle.Height - 1)); | |
g.DrawRectangle(p, modRect); | |
} | |
*/ | |
} | |
[DllImport("user32.dll")] | |
private static extern uint GetDpiForWindow(IntPtr hwnd); | |
/// <summary> | |
/// Add DropShadow to top level windows | |
/// </summary> | |
protected override CreateParams CreateParams | |
{ | |
get | |
{ | |
const int CS_DROPSHADOW = 0x20000; | |
CreateParams cp = base.CreateParams; | |
cp.ClassStyle |= CS_DROPSHADOW; | |
return cp; | |
} | |
} | |
#endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment