Last active
May 20, 2022 09:39
-
-
Save colhountech/1da87c36d1dc236c937ceae4f8b56832 to your computer and use it in GitHub Desktop.
AcrylicUI Min/Max/Restore for catching resize events to adjust form
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 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