* UIForm: 增加WindowStateChanged事件

* UIForm2: 增加WindowStateChanged事件
* UIPage: 增加WindowStateChanged事件
This commit is contained in:
Sunny 2024-04-28 14:29:46 +08:00
parent ca1ab0cfd3
commit 960d3665de
7 changed files with 129 additions and 32 deletions

View File

@ -55,6 +55,7 @@
* 2023-12-13: V3.6.2 UIPage的Init和Final加载逻辑 * 2023-12-13: V3.6.2 UIPage的Init和Final加载逻辑
* 2023-02-19: V3.6.3 * 2023-02-19: V3.6.3
* 2024-02-22: V3.6.3 Normal显示 * 2024-02-22: V3.6.3 Normal显示
* 2024-04-28: V3.6.5 WindowStateChanged事件
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -115,6 +116,24 @@ namespace Sunny.UI
set => base.AutoScroll = false; set => base.AutoScroll = false;
} }
public event OnWindowStateChanged WindowStateChanged;
private void DoWindowStateChanged(FormWindowState thisState)
{
lastWindowState = thisState;
DoWindowStateChanged(thisState, WindowState);
}
private void DoWindowStateChanged(FormWindowState thisState, FormWindowState lastState)
{
WindowStateChanged?.Invoke(this, thisState, lastState);
foreach (var page in UIStyles.Pages.Values)
{
page.DoWindowStateChanged(thisState, lastState);
}
}
/// <summary> /// <summary>
/// 禁止控件跟随窗体缩放 /// 禁止控件跟随窗体缩放
/// </summary> /// </summary>
@ -652,6 +671,7 @@ namespace Sunny.UI
if (InMinBox) if (InMinBox)
{ {
InMinBox = false; InMinBox = false;
DoWindowStateChanged(FormWindowState.Minimized);
WindowState = FormWindowState.Minimized; WindowState = FormWindowState.Minimized;
} }
@ -703,6 +723,7 @@ namespace Sunny.UI
// 若窗体从正常模式->最大化模式,该操作是由移动窗体至顶部触发的,记录的是移动前的窗体位置 // 若窗体从正常模式->最大化模式,该操作是由移动窗体至顶部触发的,记录的是移动前的窗体位置
location = IsOnMoving ? FormLocation : Location; location = IsOnMoving ? FormLocation : Location;
FormEx.SetFormRoundRectRegion(this, 0); FormEx.SetFormRoundRectRegion(this, 0);
DoWindowStateChanged(FormWindowState.Maximized);
WindowState = FormWindowState.Maximized; WindowState = FormWindowState.Maximized;
} }
else if (WindowState == FormWindowState.Maximized) else if (WindowState == FormWindowState.Maximized)
@ -725,6 +746,7 @@ namespace Sunny.UI
Location = location; Location = location;
FormEx.SetFormRoundRectRegion(this, ShowRadius ? 5 : 0); FormEx.SetFormRoundRectRegion(this, ShowRadius ? 5 : 0);
DoWindowStateChanged(FormWindowState.Normal);
WindowState = FormWindowState.Normal; WindowState = FormWindowState.Normal;
} }
@ -1745,6 +1767,7 @@ namespace Sunny.UI
#region #region
private FormWindowState lastWindowState = FormWindowState.Normal;
protected override void WndProc(ref Message m) protected override void WndProc(ref Message m)
{ {
if (m.Msg == Win32.User.WM_ERASEBKGND) if (m.Msg == Win32.User.WM_ERASEBKGND)
@ -1762,6 +1785,24 @@ namespace Sunny.UI
} }
} }
if (m.Msg == Win32.User.WM_ACTIVATE)
{
if (WindowState != FormWindowState.Minimized && lastWindowState == FormWindowState.Minimized)
{
DoWindowStateChanged(WindowState, lastWindowState);
lastWindowState = WindowState;
}
}
if (m.Msg == Win32.User.WM_ACTIVATEAPP)
{
if (WindowState == FormWindowState.Minimized && lastWindowState != FormWindowState.Minimized)
{
DoWindowStateChanged(WindowState, lastWindowState);
lastWindowState = FormWindowState.Minimized;
}
}
base.WndProc(ref m); base.WndProc(ref m);
if (m.Msg == Win32.User.WM_NCHITTEST && ShowDragStretch && WindowState == FormWindowState.Normal) if (m.Msg == Win32.User.WM_NCHITTEST && ShowDragStretch && WindowState == FormWindowState.Normal)

View File

@ -19,6 +19,7 @@
* 2024-01-20: V3.6.3 * 2024-01-20: V3.6.3
* 2024-01-25: V3.6.3 * 2024-01-25: V3.6.3
* 2024-04-16: V3.6.5 Padding.Top为TitleHeight * 2024-04-16: V3.6.5 Padding.Top为TitleHeight
* 2024-04-28: V3.6.5 WindowStateChanged事件
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -64,6 +65,24 @@ namespace Sunny.UI
public readonly Guid Guid = Guid.NewGuid(); public readonly Guid Guid = Guid.NewGuid();
public event OnWindowStateChanged WindowStateChanged;
private void DoWindowStateChanged(FormWindowState thisState)
{
lastWindowState = thisState;
DoWindowStateChanged(thisState, WindowState);
}
private void DoWindowStateChanged(FormWindowState thisState, FormWindowState lastState)
{
WindowStateChanged?.Invoke(this, thisState, lastState);
foreach (var page in UIStyles.Pages.Values)
{
page.DoWindowStateChanged(thisState, lastState);
}
}
public void Translate() public void Translate()
{ {
List<Control> controls = this.GetInterfaceControls("ITranslate"); List<Control> controls = this.GetInterfaceControls("ITranslate");
@ -660,6 +679,7 @@ namespace Sunny.UI
if (InMinBox) if (InMinBox)
{ {
InMinBox = false; InMinBox = false;
DoWindowStateChanged(FormWindowState.Minimized);
WindowState = FormWindowState.Minimized; WindowState = FormWindowState.Minimized;
} }
@ -690,11 +710,13 @@ namespace Sunny.UI
{ {
if (WindowState == FormWindowState.Maximized) if (WindowState == FormWindowState.Maximized)
{ {
DoWindowStateChanged(FormWindowState.Normal);
WindowState = FormWindowState.Normal; WindowState = FormWindowState.Normal;
if (Location.Y < 0) Location = new Point(Location.X, 0); if (Location.Y < 0) Location = new Point(Location.X, 0);
} }
else else
{ {
DoWindowStateChanged(FormWindowState.Maximized);
WindowState = FormWindowState.Maximized; WindowState = FormWindowState.Maximized;
} }
} }
@ -703,12 +725,14 @@ namespace Sunny.UI
if (WindowState == FormWindowState.Maximized) if (WindowState == FormWindowState.Maximized)
{ {
FormBorderStyle = FormBorderStyle.Sizable; FormBorderStyle = FormBorderStyle.Sizable;
DoWindowStateChanged(FormWindowState.Normal);
WindowState = FormWindowState.Normal; WindowState = FormWindowState.Normal;
if (Location.Y < 0) Location = new Point(Location.X, 0); if (Location.Y < 0) Location = new Point(Location.X, 0);
} }
else else
{ {
FormBorderStyle = FormBorderStyle.None; FormBorderStyle = FormBorderStyle.None;
DoWindowStateChanged(FormWindowState.Maximized);
WindowState = FormWindowState.Maximized; WindowState = FormWindowState.Maximized;
} }
} }
@ -1146,6 +1170,8 @@ namespace Sunny.UI
return new Size(width, height); return new Size(width, height);
} }
private FormWindowState lastWindowState = FormWindowState.Normal;
protected override void WndProc(ref Message m) protected override void WndProc(ref Message m)
{ {
var msg = (int)m.Msg; var msg = (int)m.Msg;
@ -1154,6 +1180,11 @@ namespace Sunny.UI
case Win32.User.WM_ACTIVATE: case Win32.User.WM_ACTIVATE:
var margins = new Win32.Dwm.MARGINS(0, 0, 1, 0); var margins = new Win32.Dwm.MARGINS(0, 0, 1, 0);
Win32.Dwm.DwmExtendFrameIntoClientArea(Handle, ref margins); Win32.Dwm.DwmExtendFrameIntoClientArea(Handle, ref margins);
if (WindowState != FormWindowState.Minimized && lastWindowState == FormWindowState.Minimized)
{
DoWindowStateChanged(WindowState, lastWindowState);
lastWindowState = WindowState;
}
break; break;
case Win32.User.WM_NCCALCSIZE when m.WParam != IntPtr.Zero: case Win32.User.WM_NCCALCSIZE when m.WParam != IntPtr.Zero:
if (CalcSize(ref m)) return; if (CalcSize(ref m)) return;
@ -1165,6 +1196,13 @@ namespace Sunny.UI
HotKeyEventHandler?.Invoke(this, new HotKeyEventArgs(hotKeys[hotKeyId], DateTime.Now)); HotKeyEventHandler?.Invoke(this, new HotKeyEventArgs(hotKeys[hotKeyId], DateTime.Now));
} }
break; break;
case Win32.User.WM_ACTIVATEAPP:
if (WindowState == FormWindowState.Minimized && lastWindowState != FormWindowState.Minimized)
{
DoWindowStateChanged(WindowState, lastWindowState);
lastWindowState = FormWindowState.Minimized;
}
break;
} }
base.WndProc(ref m); base.WndProc(ref m);

View File

@ -42,6 +42,8 @@ namespace Sunny.UI
public delegate void OnZoomScaleRectChanged(object sender, Rectangle info); public delegate void OnZoomScaleRectChanged(object sender, Rectangle info);
public delegate void OnWindowStateChanged(object sender, FormWindowState thisState, FormWindowState lastState);
public enum UILoginFormFocusControl public enum UILoginFormFocusControl
{ {
UserName, UserName,

View File

@ -48,6 +48,7 @@
btnCancel.Style = UIStyle.Custom; btnCancel.Style = UIStyle.Custom;
btnCancel.TabIndex = 6; btnCancel.TabIndex = 6;
btnCancel.Text = "取消"; btnCancel.Text = "取消";
btnCancel.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
btnCancel.TipsText = null; btnCancel.TipsText = null;
btnCancel.Click += btnCancel_Click; btnCancel.Click += btnCancel_Click;
// //
@ -64,6 +65,7 @@
btnOK.Style = UIStyle.Custom; btnOK.Style = UIStyle.Custom;
btnOK.TabIndex = 5; btnOK.TabIndex = 5;
btnOK.Text = "确定"; btnOK.Text = "确定";
btnOK.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
btnOK.TipsText = null; btnOK.TipsText = null;
btnOK.Click += btnOK_Click; btnOK.Click += btnOK_Click;
// //
@ -107,6 +109,7 @@
ShowInTaskbar = false; ShowInTaskbar = false;
Text = "UIMsgBox"; Text = "UIMsgBox";
ZoomScaleRect = new System.Drawing.Rectangle(15, 15, 450, 270); ZoomScaleRect = new System.Drawing.Rectangle(15, 15, 450, 270);
FormClosed += UIMessageForm_FormClosed;
Shown += UIMessageForm_Shown; Shown += UIMessageForm_Shown;
ResumeLayout(false); ResumeLayout(false);
} }

View File

@ -212,5 +212,10 @@ namespace Sunny.UI
if (delay <= 0) Close(); if (delay <= 0) Close();
} }
private void UIMessageForm_FormClosed(object sender, FormClosedEventArgs e)
{
timer1.Stop();
}
} }
} }

View File

@ -43,6 +43,7 @@
* 2023-11-06: V3.5.2 * 2023-11-06: V3.5.2
* 2023-12-04: V3.6.1 Style后BackColor未保存的问题 * 2023-12-04: V3.6.1 Style后BackColor未保存的问题
* 2023-12-20: V3.6.2 AfterShow事件位置及逻辑 * 2023-12-20: V3.6.2 AfterShow事件位置及逻辑
* 2024-04-28: V3.6.5 WindowStateChanged事件
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -56,34 +57,6 @@ namespace Sunny.UI
[DefaultEvent("Initialize")] [DefaultEvent("Initialize")]
public partial class UIPage : Form, IStyleInterface, ISymbol, IZoomScale public partial class UIPage : Form, IStyleInterface, ISymbol, IZoomScale
{ {
public readonly Guid Guid = Guid.NewGuid();
private Color _rectColor = UIColor.Blue;
private ToolStripStatusLabelBorderSides _rectSides = ToolStripStatusLabelBorderSides.None;
protected UIStyle _style = UIStyle.Inherited;
[Browsable(false)]
public IFrame Frame
{
get; set;
}
private bool extendBox;
[DefaultValue(false)]
[Description("显示扩展按钮"), Category("SunnyUI")]
public bool ExtendBox
{
get => extendBox;
set
{
extendBox = showTitle && value;
CalcSystemBoxPos();
Invalidate();
}
}
public UIPage() public UIPage()
{ {
InitializeComponent(); InitializeComponent();
@ -115,6 +88,41 @@ namespace Sunny.UI
base.SizeGripStyle = SizeGripStyle.Hide; base.SizeGripStyle = SizeGripStyle.Hide;
} }
public readonly Guid Guid = Guid.NewGuid();
private Color _rectColor = UIColor.Blue;
private ToolStripStatusLabelBorderSides _rectSides = ToolStripStatusLabelBorderSides.None;
protected UIStyle _style = UIStyle.Inherited;
[Browsable(false)]
public IFrame Frame
{
get; set;
}
private bool extendBox;
[DefaultValue(false)]
[Description("显示扩展按钮"), Category("SunnyUI")]
public bool ExtendBox
{
get => extendBox;
set
{
extendBox = showTitle && value;
CalcSystemBoxPos();
Invalidate();
}
}
public event OnWindowStateChanged WindowStateChanged;
internal void DoWindowStateChanged(FormWindowState thisState, FormWindowState lastState)
{
WindowStateChanged?.Invoke(this, thisState, lastState);
}
protected override void OnClick(EventArgs e) protected override void OnClick(EventArgs e)
{ {
base.OnClick(e); base.OnClick(e);

View File

@ -204,10 +204,10 @@ namespace Sunny.UI
SetStyle(UIStyle.Colorful); SetStyle(UIStyle.Colorful);
} }
private static readonly ConcurrentDictionary<UIStyle, UIBaseStyle> Styles = new ConcurrentDictionary<UIStyle, UIBaseStyle>(); internal static readonly ConcurrentDictionary<UIStyle, UIBaseStyle> Styles = new ConcurrentDictionary<UIStyle, UIBaseStyle>();
private static readonly ConcurrentDictionary<Guid, UIForm> Forms = new ConcurrentDictionary<Guid, UIForm>(); internal static readonly ConcurrentDictionary<Guid, UIForm> Forms = new ConcurrentDictionary<Guid, UIForm>();
private static readonly ConcurrentDictionary<Guid, UIPage> Pages = new ConcurrentDictionary<Guid, UIPage>(); internal static readonly ConcurrentDictionary<Guid, UIPage> Pages = new ConcurrentDictionary<Guid, UIPage>();
private static readonly ConcurrentDictionary<Guid, UIForm2> Forms2 = new ConcurrentDictionary<Guid, UIForm2>(); internal static readonly ConcurrentDictionary<Guid, UIForm2> Forms2 = new ConcurrentDictionary<Guid, UIForm2>();
/// <summary> /// <summary>