* UITextBox: 增加了只读的颜色设置

This commit is contained in:
Sunny 2022-02-16 15:29:08 +08:00
parent 4400968ade
commit cee61dd7cb
3 changed files with 47 additions and 13 deletions

Binary file not shown.

View File

@ -70,6 +70,8 @@ namespace Sunny.UI
} }
} }
protected bool isReadOnly;
protected void SetStyleFlags(bool supportTransparent = true, bool selectable = true, bool resizeRedraw = false) protected void SetStyleFlags(bool supportTransparent = true, bool selectable = true, bool resizeRedraw = false)
{ {
SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true);
@ -407,7 +409,7 @@ namespace Sunny.UI
protected virtual void OnPaintFore(Graphics g, GraphicsPath path) protected virtual void OnPaintFore(Graphics g, GraphicsPath path)
{ {
g.DrawString(Text, Font, Enabled ? foreColor : foreDisableColor, Size, Padding, TextAlignment); g.DrawString(Text, Font, GetForeColor(), Size, Padding, TextAlignment);
} }
protected virtual void OnPaintRect(Graphics g, GraphicsPath path) protected virtual void OnPaintRect(Graphics g, GraphicsPath path)
@ -525,6 +527,18 @@ namespace Sunny.UI
{ {
} }
protected virtual void AfterSetFillReadOnlyColor(Color color)
{
}
protected virtual void AfterSetRectReadOnlyColor(Color color)
{
}
protected virtual void AfterSetForeReadOnlyColor(Color color)
{
}
/// <summary> /// <summary>
/// 自定义主题风格 /// 自定义主题风格
/// </summary> /// </summary>
@ -597,7 +611,9 @@ namespace Sunny.UI
protected void SetFillReadOnlyColor(Color color) protected void SetFillReadOnlyColor(Color color)
{ {
fillReadOnlyColor = color; fillReadOnlyColor = color;
AfterSetFillReadOnlyColor(color);
_style = UIStyle.Custom; _style = UIStyle.Custom;
Invalidate();
} }
/// <summary> /// <summary>
@ -607,7 +623,9 @@ namespace Sunny.UI
protected void SetRectReadOnlyColor(Color color) protected void SetRectReadOnlyColor(Color color)
{ {
rectReadOnlyColor = color; rectReadOnlyColor = color;
AfterSetRectReadOnlyColor(color);
_style = UIStyle.Custom; _style = UIStyle.Custom;
Invalidate();
} }
/// <summary> /// <summary>
@ -617,7 +635,9 @@ namespace Sunny.UI
protected void SetForeReadOnlyColor(Color color) protected void SetForeReadOnlyColor(Color color)
{ {
foreReadOnlyColor = color; foreReadOnlyColor = color;
AfterSetForeReadOnlyColor(color);
_style = UIStyle.Custom; _style = UIStyle.Custom;
Invalidate();
} }
/// <summary> /// <summary>
@ -671,17 +691,17 @@ namespace Sunny.UI
protected Color GetRectColor() protected Color GetRectColor()
{ {
return Enabled ? rectColor : rectDisableColor; return Enabled ? (isReadOnly ? rectReadOnlyColor : rectColor) : rectDisableColor;
} }
protected Color GetForeColor() protected Color GetForeColor()
{ {
return Enabled ? foreColor : foreDisableColor; return Enabled ? (isReadOnly ? foreReadOnlyColor : foreColor) : foreDisableColor;
} }
protected Color GetFillColor() protected Color GetFillColor()
{ {
return Enabled ? fillColor : fillDisableColor; return Enabled ? (isReadOnly ? fillReadOnlyColor : fillColor) : fillDisableColor;
} }
/// <summary> /// <summary>

View File

@ -30,6 +30,7 @@
* 2021-10-14: V3.0.8 * 2021-10-14: V3.0.8
* 2021-10-15: V3.0.8 * 2021-10-15: V3.0.8
* 2022-01-07: V3.1.0 * 2022-01-07: V3.1.0
* 2022-02-16: V3.1.1
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -275,7 +276,7 @@ namespace Sunny.UI
protected override void OnEnabledChanged(EventArgs e) protected override void OnEnabledChanged(EventArgs e)
{ {
base.OnEnabledChanged(e); base.OnEnabledChanged(e);
edit.BackColor = Enabled ? FillColor : FillDisableColor; edit.BackColor = GetFillColor();
edit.Enabled = Enabled; edit.Enabled = Enabled;
} }
@ -529,8 +530,6 @@ namespace Sunny.UI
} }
} }
private void SizeChange() private void SizeChange()
{ {
if (!InitializeComponentEnd) return; if (!InitializeComponentEnd) return;
@ -614,11 +613,13 @@ namespace Sunny.UI
[Description("是否只读"), Category("SunnyUI")] [Description("是否只读"), Category("SunnyUI")]
public bool ReadOnly public bool ReadOnly
{ {
get => edit.ReadOnly; get => isReadOnly;
set set
{ {
isReadOnly = value;
edit.ReadOnly = value; edit.ReadOnly = value;
edit.BackColor = Enabled ? FillColor : FillDisableColor; edit.BackColor = GetFillColor();
Invalidate();
} }
} }
@ -764,8 +765,9 @@ namespace Sunny.UI
if (uiColor.IsCustom()) return; if (uiColor.IsCustom()) return;
fillColor = uiColor.EditorBackColor; fillColor = uiColor.EditorBackColor;
edit.BackColor = Enabled ? fillColor : FillDisableColor; foreColor = UIFontColor.Primary;
edit.ForeColor = foreColor = UIFontColor.Primary; edit.BackColor = GetFillColor();
edit.ForeColor = GetForeColor();
if (bar != null) if (bar != null)
{ {
@ -796,13 +798,25 @@ namespace Sunny.UI
protected override void AfterSetForeColor(Color color) protected override void AfterSetForeColor(Color color)
{ {
base.AfterSetForeColor(color); base.AfterSetForeColor(color);
edit.ForeColor = color; edit.ForeColor = GetForeColor();
} }
protected override void AfterSetFillColor(Color color) protected override void AfterSetFillColor(Color color)
{ {
base.AfterSetFillColor(color); base.AfterSetFillColor(color);
edit.BackColor = Enabled ? color : FillDisableColor; edit.BackColor = GetFillColor();
}
protected override void AfterSetFillReadOnlyColor(Color color)
{
base.AfterSetFillReadOnlyColor(color);
edit.BackColor = GetFillColor();
}
protected override void AfterSetForeReadOnlyColor(Color color)
{
base.AfterSetForeReadOnlyColor(color);
edit.ForeColor = GetForeColor();
} }
public enum UIEditType public enum UIEditType