* UITextBox: 修复了Enabled为false时,字体大小调整后,文字显示位置的问题
This commit is contained in:
parent
f800b16554
commit
3fe1a5bf17
@ -55,16 +55,6 @@ namespace Sunny.UI
|
|||||||
this.TextChanged += new EventHandler(ThisTextChanged);
|
this.TextChanged += new EventHandler(ThisTextChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Enable属性变更
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
protected override void OnEnabledChanged(EventArgs e)
|
|
||||||
{
|
|
||||||
SetStyle(ControlStyles.UserPaint, !Enabled);
|
|
||||||
base.OnEnabledChanged(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DrawWaterMark()
|
private void DrawWaterMark()
|
||||||
{
|
{
|
||||||
if (this.waterMarkContainer == null && this.TextLength <= 0)
|
if (this.waterMarkContainer == null && this.TextLength <= 0)
|
||||||
@ -168,28 +158,6 @@ namespace Sunny.UI
|
|||||||
{
|
{
|
||||||
base.OnPaint(e);
|
base.OnPaint(e);
|
||||||
DrawWaterMark();
|
DrawWaterMark();
|
||||||
|
|
||||||
if (Text.IsValid() && !Enabled)
|
|
||||||
{
|
|
||||||
string text = Text;
|
|
||||||
if (PasswordChar > 0)
|
|
||||||
{
|
|
||||||
text = PasswordChar.ToString().Repeat(text.Length);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TextAlign == HorizontalAlignment.Left)
|
|
||||||
{
|
|
||||||
e.Graphics.DrawString(text, Font, ForeDisableColor, new Rectangle(0, 0, Width, Height), ContentAlignment.MiddleLeft, -5, 0);
|
|
||||||
}
|
|
||||||
else if (TextAlign == HorizontalAlignment.Right)
|
|
||||||
{
|
|
||||||
e.Graphics.DrawString(text, Font, ForeDisableColor, new Rectangle(0, 0, Width, Height), ContentAlignment.MiddleRight, 7, 0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
e.Graphics.DrawString(text, Font, ForeDisableColor, new Rectangle(0, 0, Width, Height), ContentAlignment.MiddleCenter, 1, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Color ForeDisableColor { get; set; } = Color.FromArgb(109, 109, 103);
|
public virtual Color ForeDisableColor { get; set; } = Color.FromArgb(109, 109, 103);
|
||||||
|
@ -49,6 +49,7 @@
|
|||||||
* 2023-06-14: V3.3.9 按钮图标位置修正
|
* 2023-06-14: V3.3.9 按钮图标位置修正
|
||||||
* 2023-07-03: V3.3.9 增加Enabled为false时,可修改文字颜色
|
* 2023-07-03: V3.3.9 增加Enabled为false时,可修改文字颜色
|
||||||
* 2023-07-16: V3.4.0 修复了Enabled为false时,PasswordChar失效的问题
|
* 2023-07-16: V3.4.0 修复了Enabled为false时,PasswordChar失效的问题
|
||||||
|
* 2023-08-17: V3.4.1 修复了Enabled为false时,字体大小调整后,文字显示位置的问题
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -412,7 +413,7 @@ namespace Sunny.UI
|
|||||||
{
|
{
|
||||||
base.OnEnabledChanged(e);
|
base.OnEnabledChanged(e);
|
||||||
edit.BackColor = GetFillColor();
|
edit.BackColor = GetFillColor();
|
||||||
edit.Enabled = Enabled;
|
edit.Visible = Enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Focused => edit.Focused;
|
public override bool Focused => edit.Focused;
|
||||||
@ -1269,6 +1270,34 @@ namespace Sunny.UI
|
|||||||
{
|
{
|
||||||
e.Graphics.DrawFontImage(Symbol, SymbolSize, SymbolColor, new Rectangle(4 + symbolOffset.X, (Height - SymbolSize) / 2 + 1 + symbolOffset.Y, SymbolSize, SymbolSize), SymbolOffset.X, SymbolOffset.Y);
|
e.Graphics.DrawFontImage(Symbol, SymbolSize, SymbolColor, new Rectangle(4 + symbolOffset.X, (Height - SymbolSize) / 2 + 1 + symbolOffset.Y, SymbolSize, SymbolSize), SymbolOffset.X, SymbolOffset.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Text.IsValid() && !Enabled)
|
||||||
|
{
|
||||||
|
string text = Text;
|
||||||
|
if (PasswordChar > 0)
|
||||||
|
{
|
||||||
|
text = PasswordChar.ToString().Repeat(text.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
ContentAlignment textAlign = ContentAlignment.MiddleLeft;
|
||||||
|
if (TextAlignment == ContentAlignment.TopCenter || TextAlignment == ContentAlignment.MiddleCenter || TextAlignment == ContentAlignment.BottomCenter)
|
||||||
|
textAlign = ContentAlignment.MiddleCenter;
|
||||||
|
|
||||||
|
if (TextAlignment == ContentAlignment.TopRight || TextAlignment == ContentAlignment.MiddleRight || TextAlignment == ContentAlignment.BottomRight)
|
||||||
|
textAlign = ContentAlignment.MiddleRight;
|
||||||
|
|
||||||
|
Size sf = TextRenderer.MeasureText(text, edit.Font);
|
||||||
|
using (Brush br = new SolidBrush(ForeDisableColor))
|
||||||
|
{
|
||||||
|
if (textAlign == ContentAlignment.MiddleLeft)
|
||||||
|
e.Graphics.DrawString(text, Font, br, new Point(edit.Left + 1 - Math.Min((int)(Font.Size / 3), 4), ((Height - sf.Height) / 2.0).RoundEx() - 1));
|
||||||
|
if (textAlign == ContentAlignment.MiddleCenter)
|
||||||
|
e.Graphics.DrawString(text, Font, br, new Point(edit.Left + (int)((edit.Width - sf.Width) / 2) + (Font.Size < 10 ? 1 : 2), ((Height - sf.Height) / 2.0).RoundEx() - 1));
|
||||||
|
if (textAlign == ContentAlignment.MiddleRight)
|
||||||
|
e.Graphics.DrawString(text, Font, br, new Point(edit.Left + edit.Width - sf.Width - 3 + Math.Min((int)(sf.Height / 2), 10), ((Height - sf.Height) / 2.0).RoundEx() - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Color _symbolColor = UIFontColor.Primary;
|
public Color _symbolColor = UIFontColor.Primary;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user