Skip to content

Instantly share code, notes, and snippets.

@colhountech
Last active May 20, 2022 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colhountech/1da87c36d1dc236c937ceae4f8b56832 to your computer and use it in GitHub Desktop.
Save colhountech/1da87c36d1dc236c937ceae4f8b56832 to your computer and use it in GitHub Desktop.
AcrylicUI Min/Max/Restore for catching resize events to adjust form
#region Min/Max/Restore for catching resize events to adjust form
private void BtnMin_Click(object sender, EventArgs e)
{
_restoreSize = ClientSize;
this.WindowState = FormWindowState.Minimized;
AdjustForm();
}
private void BtnMaximize_Click(object sender, EventArgs e)
{
_restoreSize = ClientSize;
this.WindowState = (this.WindowState == FormWindowState.Normal ? FormWindowState.Maximized : FormWindowState.Normal);
AdjustForm();
}
protected override void OnResizeBegin(EventArgs e)
{
this.SuspendLayout();
base.OnResizeBegin(e);
}
protected override void OnResizeEnd(EventArgs e)
{
base.OnResizeEnd(e);
this.ResumeLayout();
}
protected override void OnResize(EventArgs e)
{
this.SuspendLayout();
base.OnResize(e);
AdjustForm();
this.ResumeLayout();
}
private void AdjustForm()
{
switch (this.WindowState)
{
case FormWindowState.Maximized: //Maximized form (After)
this.Padding = new Padding(8, 8, 8, 8);
break;
case FormWindowState.Normal: //Restored form (After)
if (this.Padding.Top != borderSize)
this.Padding = new Padding(borderSize);
break;
}
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (e.Clicks == 2) // DoubleClick
{
BtnMaximize_Click(this, e);
}
else
{
WinProcExtentsions.TitleBarHit(Handle);
}
}
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment