Files
PDFPatcher/App/Functions/FormState.cs
T
Calcitem a25ebdfd4d 部分 if 条件翻转以缩小代码嵌套层级
一般是在 if 控制范围很大的情况下进行调整,如果控制范围小则不调整。
从第三方代码的 Demo 中复制的代码块不修改。
2022-01-15 09:39:10 +08:00

46 lines
1.0 KiB
C#

using System.Drawing;
using System.Windows.Forms;
namespace PDFPatcher.Functions
{
/// <summary>
/// Class used to preserve / restore / maximize state of the form
/// </summary>
public sealed class FormState
{
FormBorderStyle brdStyle;
bool topMost;
Rectangle bounds;
bool IsMaximized;
public void Maximize(Form targetForm) {
if (IsMaximized) {
return;
}
IsMaximized = true;
if (targetForm.WindowState == FormWindowState.Maximized) {
targetForm.WindowState = FormWindowState.Normal;
}
Save(targetForm);
targetForm.FormBorderStyle = FormBorderStyle.None;
targetForm.TopMost = true;
targetForm.Bounds = Screen.FromControl(targetForm).Bounds;
}
void Save(Form targetForm) {
brdStyle = targetForm.FormBorderStyle;
topMost = targetForm.TopMost;
bounds = targetForm.Bounds;
}
public void Restore(Form targetForm) {
targetForm.FormBorderStyle = brdStyle;
targetForm.TopMost = topMost;
targetForm.Bounds = bounds;
IsMaximized = false;
}
}
}