* UIPage:修复OnLoad在加载时重复加载两次的问题,增加Final函数,每次页面切换,退出页面都会执行

This commit is contained in:
Sunny 2021-07-18 00:06:47 +08:00
parent 16091b91b0
commit e801c64974
9 changed files with 82 additions and 35 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -14,32 +14,39 @@ namespace Sunny.UI.Demo
}
/// <summary>
/// 放在 [窗体Load、重载OnLoad、重载Init] 的内容每次页面切换都会执行。
/// 放在 [窗体Load、重载OnLoad、重载Init] 的内容每次页面切换,进入页面都会执行。
/// 这三个选一个用就行了。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FButton_Load(object sender, EventArgs e)
{
uiSwitch1.Active = uiSwitch4.Active = true;
uiSwitch2.Active = uiSwitch3.Active = false;
Console.WriteLine("1. FButton_Load");
}
//放在 [窗体Load、重载OnLoad、重载Init] 的内容每次页面切换都会执行。
//protected override void OnLoad(EventArgs e)
//{
// base.OnLoad(e);
// uiSwitch1.Active = uiSwitch4.Active = true;
// uiSwitch2.Active = uiSwitch3.Active = false;
//}
//放在 [窗体Load、重载OnLoad、重载Init] 的内容每次页面切换,进入页面都会执行。
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Console.WriteLine("3. FButton_OnLoad");
}
//放在 [窗体Load、重载OnLoad、重载Init] 的内容每次页面切换都会执行。
//public override void Init()
//{
// base.Init();
// uiSwitch1.Active = uiSwitch4.Active = true;
// uiSwitch2.Active = uiSwitch3.Active = false;
//}
//放在 [窗体Load、重载OnLoad、重载Init] 的内容每次页面切换,进入页面都会执行。
public override void Init()
{
base.Init();
uiSwitch1.Active = uiSwitch4.Active = true;
uiSwitch2.Active = uiSwitch3.Active = false;
Console.WriteLine("2. FButton_Init");
}
//放在 [Final] 的内容每次页面切换,退出页面都会执行
public override void Final()
{
base.Final();
Console.WriteLine("4. FButton_Final");
}
private void uiButton10_Click(object sender, EventArgs e)
{

View File

@ -21,13 +21,13 @@
* 2020-08-12: V2.2.7
******************************************************************************/
using Sunny.UI.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using Sunny.UI.Win32;
namespace Sunny.UI
{
@ -127,7 +127,10 @@ namespace Sunny.UI
public void AddPage(Guid guid, UITabControlMenu page) => Helper.AddPage(guid, page);
public string Version { get; }
public string Version
{
get;
}
private Color _fillColor = UIColor.LightBlue;
private Color tabBackColor = Color.FromArgb(56, 56, 56);
@ -137,14 +140,20 @@ namespace Sunny.UI
/// </summary>
[DefaultValue(null)]
[Description("获取或设置包含有关控件的数据的对象字符串"), Category("SunnyUI")]
public string TagString { get; set; }
public string TagString
{
get; set;
}
/// <summary>
/// 自定义主题风格
/// </summary>
[DefaultValue(false)]
[Description("获取或设置可以自定义主题风格"), Category("SunnyUI")]
public bool StyleCustomMode { get; set; }
public bool StyleCustomMode
{
get; set;
}
private HorizontalAlignment textAlignment = HorizontalAlignment.Center;
@ -555,7 +564,10 @@ namespace Sunny.UI
[DefaultValue(false)]
[Description("多页面框架时包含UIPage在点击Tab页关闭时关闭UIPage"), Category("SunnyUI")]
public bool AutoClosePage { get; set; }
public bool AutoClosePage
{
get; set;
}
internal void RemoveTabPage(int index)
{
@ -608,27 +620,44 @@ namespace Sunny.UI
protected override void OnSelectedIndexChanged(EventArgs e)
{
base.OnSelectedIndexChanged(e);
Init(SelectedIndex);
Init();
if (ShowActiveCloseButton && !ShowCloseButton)
{
timer.Start();
}
}
public void Init(int index = 0)
private int LastIndex = 0;
public void Init()
{
if (index < 0 || index >= TabPages.Count)
if (SelectedIndex < 0 || SelectedIndex >= TabPages.Count)
{
return;
}
if (SelectedIndex != index)
SelectedIndex = index;
List<UIPage> pages = TabPages[SelectedIndex].GetControls<UIPage>();
foreach (var page in pages)
if (SelectedIndex >= 0)
{
page.ReLoad();
List<UIPage> pages;
if (LastIndex != SelectedIndex)
{
if (LastIndex >= 0 && TabPages.Count > 0)
{
pages = TabPages[LastIndex].GetControls<UIPage>();
foreach (var page in pages)
{
page.Final();
}
}
LastIndex = SelectedIndex;
}
pages = TabPages[SelectedIndex].GetControls<UIPage>();
foreach (var page in pages)
{
page.ReLoad();
}
}
List<UITabControlMenu> leftTabControls = TabPages[SelectedIndex].GetControls<UITabControlMenu>();
@ -901,11 +930,20 @@ namespace Sunny.UI
MouseInUpButton = mouseInUpButton;
}
public bool MouseOver { get; }
public bool MouseOver
{
get;
}
public bool MousePress { get; }
public bool MousePress
{
get;
}
public bool MouseInUpButton { get; }
public bool MouseInUpButton
{
get;
}
}
}
}

View File

@ -217,6 +217,7 @@ namespace Sunny.UI
}
public event EventHandler Initialize;
public event EventHandler Finalize;
protected override void OnControlAdded(ControlEventArgs e)
{
@ -260,7 +261,7 @@ namespace Sunny.UI
public virtual void Init()
{
Initialize?.Invoke(this, null);
Initialize?.Invoke(this, new EventArgs());
}
protected override void OnLoad(EventArgs e)
@ -292,6 +293,7 @@ namespace Sunny.UI
public virtual void Final()
{
Finalize?.Invoke(this, new EventArgs());
}
public void SetStyle(UIStyle style)