* UISwitch: 增加ActiveChanging事件,在状态改变前可以进行判断

This commit is contained in:
Sunny 2023-04-23 22:30:05 +08:00
parent c16d77bbcd
commit c91be03a49
2 changed files with 22 additions and 2 deletions

View File

@ -20,6 +20,7 @@
******************************************************************************/
using System;
using System.ComponentModel;
using System.Reflection;
namespace Sunny.UI
@ -71,6 +72,8 @@ namespace Sunny.UI
public delegate void OnDateTimeChanged(object sender, UIDateTimeArgs e);
public delegate void OnCancelEventArgs(object sender, CancelEventArgs e);
public enum NumPadType
{
Text,

View File

@ -23,6 +23,7 @@
* 2022-01-02: V3.0.9
* 2022-03-19: V3.1.1
* 2022-09-26: V3.2.4 Readonly时
* 2022-04-23: V3.3.5 ActiveChanging事件
******************************************************************************/
using System;
@ -189,7 +190,7 @@ namespace Sunny.UI
/// <param name="e">参数</param>
protected override void OnClick(EventArgs e)
{
Active = !Active;
ActiveChange();
base.OnClick(e);
}
@ -197,7 +198,7 @@ namespace Sunny.UI
{
if (!UseDoubleClick)
{
Active = !Active;
ActiveChange();
base.OnClick(e);
}
else
@ -206,6 +207,22 @@ namespace Sunny.UI
}
}
public event OnCancelEventArgs ActiveChanging;
private void ActiveChange()
{
CancelEventArgs e = new CancelEventArgs();
if (ActiveChanging != null)
{
ActiveChanging?.Invoke(this, e);
}
if (!e.Cancel)
{
Active = !Active;
}
}
/// <summary>
/// 设置主题样式
/// </summary>