TextBox增加TextChange事件

This commit is contained in:
sunny 2020-05-15 10:22:35 +08:00
parent 8efffc058d
commit 5f92d504b0
11 changed files with 110 additions and 97 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -20,9 +20,6 @@
******************************************************************************/
using Sunny.UI.Properties;
using System.Collections.Generic;
using System.Reflection;
using System.Windows.Forms;
namespace Sunny.UI
{
@ -35,88 +32,5 @@ namespace Sunny.UI
/// 版本
/// </summary>
public static string Version = Resources.Name + " " + Resources.Version;
public static bool IsCustom(this UIStyle style)
{
return style.Equals(UIStyle.Custom);
}
public static bool IsValid(this UIStyle style)
{
return !style.IsCustom();
}
public static bool IsCustom(this UIBaseStyle style)
{
return style.Name.IsCustom();
}
public static bool IsValid(this UIBaseStyle style)
{
return !style.IsCustom();
}
public static void SetChildUIStyle(Control ctrl, UIStyle style)
{
List<Control> controls = ctrl.GetUIStyleControls("IStyleInterface");
foreach (var control in controls)
{
if (control is IStyleInterface item)
{
if (!item.StyleCustomMode)
{
item.Style = style;
}
}
}
FieldInfo[] fieldInfo = ctrl.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
foreach (var info in fieldInfo)
{
if (info.FieldType.Name == "UIContextMenuStrip")
{
UIContextMenuStrip context = (UIContextMenuStrip)info.GetValue(ctrl);
if (context != null && !context.StyleCustomMode)
{
context.SetStyle(style);
}
}
}
}
/// <summary>
/// 查找包含接口名称的控件列表
/// </summary>
/// <param name="ctrl">容器</param>
/// <param name="interfaceName">接口名称</param>
/// <returns>控件列表</returns>
private static List<Control> GetUIStyleControls(this Control ctrl, string interfaceName)
{
List<Control> values = new List<Control>();
foreach (Control obj in ctrl.Controls)
{
if (obj.GetType().GetInterface(interfaceName) != null)
{
values.Add(obj);
}
if (obj is UIPage) continue;
if (obj is UIPanel) continue;
if (obj.Controls.Count > 0)
{
values.AddRange(obj.GetUIStyleControls(interfaceName));
}
}
return values;
}
public static void ReStart(this Timer timer)
{
timer.Stop();
timer.Start();
}
}
}

View File

@ -442,7 +442,7 @@ namespace Sunny.UI
public void SetStyle(UIStyle style)
{
UIGlobal.SetChildUIStyle(this, style);
this.SetChildUIStyle(style);
SetStyleColor(UIStyles.GetStyleColor(style));
_style = style;

View File

@ -56,21 +56,17 @@ namespace Sunny.UI
edit.SelectAll();
}
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged(e);
edit.Text = Text;
Invalidate();
}
public void CheckMaxMin()
{
edit.CheckMaxMin();
}
[Browsable(true)]
public new event EventHandler TextChanged;
private void EditTextChanged(object s, EventArgs e)
{
Text = edit.Text;
TextChanged?.Invoke(this, e);
}
protected override void OnFontChanged(EventArgs e)

View File

@ -613,7 +613,7 @@ namespace Sunny.UI
public void SetStyle(UIStyle style)
{
UIGlobal.SetChildUIStyle(this, style);
this.SetChildUIStyle(style);
btn.SetStyle(style);
SetStyleColor(UIStyles.GetStyleColor(style));

View File

@ -122,7 +122,7 @@ namespace Sunny.UI
public void SetStyle(UIStyle style)
{
UIGlobal.SetChildUIStyle(this, style);
this.SetChildUIStyle(style);
SetStyleColor(UIStyles.GetStyleColor(style));
_style = style;

View File

@ -37,6 +37,12 @@ namespace Sunny.UI
/// </summary>
public static class ControlEx
{
public static void ReStart(this Timer timer)
{
timer.Stop();
timer.Start();
}
public static Form GetParentForm(this Control ctrl)
{
while (!IsForm(ctrl.Parent))

View File

@ -21,7 +21,9 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
namespace Sunny.UI
@ -640,4 +642,99 @@ namespace Sunny.UI
/// </summary>
public static readonly Color Transparent = Color.Transparent;
}
public static class UIStyleHelper
{
public static bool IsCustom(this UIStyle style)
{
return style.Equals(UIStyle.Custom);
}
public static bool IsValid(this UIStyle style)
{
return !style.IsCustom();
}
public static bool IsCustom(this UIBaseStyle style)
{
return style.Name.IsCustom();
}
public static bool IsValid(this UIBaseStyle style)
{
return !style.IsCustom();
}
public static void SetChildUIStyle(this UIPanel ctrl, UIStyle style)
{
SetControlChildUIStyle(ctrl, style);
}
public static void SetChildUIStyle(this UIForm ctrl, UIStyle style)
{
SetControlChildUIStyle(ctrl, style);
}
public static void SetChildUIStyle(this UIPage ctrl, UIStyle style)
{
SetControlChildUIStyle(ctrl, style);
}
private static void SetControlChildUIStyle(Control ctrl, UIStyle style)
{
List<Control> controls = ctrl.GetUIStyleControls("IStyleInterface");
foreach (var control in controls)
{
if (control is IStyleInterface item)
{
if (!item.StyleCustomMode)
{
item.Style = style;
}
}
}
FieldInfo[] fieldInfo = ctrl.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
foreach (var info in fieldInfo)
{
if (info.FieldType.Name == "UIContextMenuStrip")
{
UIContextMenuStrip context = (UIContextMenuStrip)info.GetValue(ctrl);
if (context != null && !context.StyleCustomMode)
{
context.SetStyle(style);
}
}
}
}
/// <summary>
/// 查找包含接口名称的控件列表
/// </summary>
/// <param name="ctrl">容器</param>
/// <param name="interfaceName">接口名称</param>
/// <returns>控件列表</returns>
private static List<Control> GetUIStyleControls(this Control ctrl, string interfaceName)
{
List<Control> values = new List<Control>();
foreach (Control obj in ctrl.Controls)
{
if (obj.GetType().GetInterface(interfaceName) != null)
{
values.Add(obj);
}
if (obj is UIPage) continue;
if (obj is UIPanel) continue;
if (obj.Controls.Count > 0)
{
values.AddRange(obj.GetUIStyleControls(interfaceName));
}
}
return values;
}
}
}