mirror of
https://gitee.com/AntdUI/AntdUI.git
synced 2026-03-25 07:00:43 +08:00
👾 修复 窗口最大值二次放大、补全 TextRenderingHighQuality Size 转换、Input 使用 WM_CHAR 替换 KeyPress、DatePicker等控件 清空内容后 失焦还会填充Value、新增 ControlEvent 在 Modal/Drawer/Popover 中通知加载成功、Table 编辑模式文本框高度异常
This commit is contained in:
@@ -165,6 +165,7 @@ namespace AntdUI
|
||||
void RotateTransform(float angle);
|
||||
float DpiX { get; }
|
||||
float DpiY { get; }
|
||||
Matrix Transform { get; set; }
|
||||
CompositingMode CompositingMode { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace AntdUI.Core
|
||||
{
|
||||
using (var path = new GraphicsPath())
|
||||
{
|
||||
path.AddString(text, font.FontFamily, (int)font.Style, font.Size * (g.DpiY / 72), rect, format);
|
||||
path.AddString(text, font.FontFamily, (int)font.Style, StringPathFontSize(font), rect, format);
|
||||
Fill(brush, path);
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@ namespace AntdUI.Core
|
||||
{
|
||||
using (var path = new GraphicsPath())
|
||||
{
|
||||
path.AddString(text, font.FontFamily, (int)font.Style, font.Size * (g.DpiY / 72), rect, format);
|
||||
path.AddString(text, font.FontFamily, (int)font.Style, StringPathFontSize(font), rect, format);
|
||||
Fill(brush, path);
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,7 @@ namespace AntdUI.Core
|
||||
{
|
||||
using (var path = new GraphicsPath())
|
||||
{
|
||||
path.AddString(text, font.FontFamily, (int)font.Style, font.Size * (g.DpiY / 72), new Point(x, y), null);
|
||||
path.AddString(text, font.FontFamily, (int)font.Style, StringPathFontSize(font), new Point(x, y), null);
|
||||
Fill(brush, path);
|
||||
}
|
||||
}
|
||||
@@ -124,7 +124,7 @@ namespace AntdUI.Core
|
||||
{
|
||||
using (var path = new GraphicsPath())
|
||||
{
|
||||
path.AddString(text, font.FontFamily, (int)font.Style, font.Size * (g.DpiY / 72), new PointF(x, y), null);
|
||||
path.AddString(text, font.FontFamily, (int)font.Style, StringPathFontSize(font), new PointF(x, y), null);
|
||||
Fill(brush, path);
|
||||
}
|
||||
}
|
||||
@@ -147,7 +147,7 @@ namespace AntdUI.Core
|
||||
{
|
||||
using (var path = new GraphicsPath())
|
||||
{
|
||||
path.AddString(text, font.FontFamily, (int)font.Style, font.Size * (g.DpiY / 72), point, null);
|
||||
path.AddString(text, font.FontFamily, (int)font.Style, StringPathFontSize(font), point, null);
|
||||
Fill(brush, path);
|
||||
}
|
||||
}
|
||||
@@ -170,13 +170,36 @@ namespace AntdUI.Core
|
||||
{
|
||||
using (var path = new GraphicsPath())
|
||||
{
|
||||
path.AddString(text, font.FontFamily, (int)font.Style, font.Size * (g.DpiY / 72), point, null);
|
||||
path.AddString(text, font.FontFamily, (int)font.Style, StringPathFontSize(font), point, null);
|
||||
Fill(brush, path);
|
||||
}
|
||||
}
|
||||
else g.DrawString(text, font, brush, point);
|
||||
}
|
||||
|
||||
float StringPathFontSize(Font font)
|
||||
{
|
||||
switch (font.Unit)
|
||||
{
|
||||
case GraphicsUnit.Point:
|
||||
return font.Size * (g.DpiY / 72);
|
||||
case GraphicsUnit.Pixel:
|
||||
return font.Size;
|
||||
case GraphicsUnit.Inch:
|
||||
return font.Size * g.DpiY;
|
||||
case GraphicsUnit.Display:
|
||||
return font.Size * .01F * g.DpiY;
|
||||
case GraphicsUnit.Document:
|
||||
return font.Size * (1 / 300F) * g.DpiY;
|
||||
case GraphicsUnit.Millimeter:
|
||||
return font.Size * (1 / 25.4F) * g.DpiY;
|
||||
case GraphicsUnit.World:
|
||||
return font.Size * g.PageScale;
|
||||
default:
|
||||
return font.Size * (g.DpiY / 72);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Image
|
||||
@@ -720,6 +743,11 @@ namespace AntdUI.Core
|
||||
public void RotateTransform(float angle) => g.RotateTransform(angle);
|
||||
public float DpiX => g.DpiX;
|
||||
public float DpiY => g.DpiY;
|
||||
public Matrix Transform
|
||||
{
|
||||
get => g.Transform;
|
||||
set => g.Transform = value;
|
||||
}
|
||||
public CompositingMode CompositingMode
|
||||
{
|
||||
get => g.CompositingMode;
|
||||
|
||||
@@ -227,6 +227,7 @@ namespace AntdUI
|
||||
ExpandDrop = false;
|
||||
if (IsHandleCreated)
|
||||
{
|
||||
if (IsTextEmpty) return;
|
||||
if (DateTime.TryParseExact(Text, Format, CultureInfo.InvariantCulture, DateTimeStyles.None, out var _d))
|
||||
{
|
||||
Value = _d;
|
||||
|
||||
@@ -354,6 +354,7 @@ namespace AntdUI
|
||||
AnimationBarValue = RectangleF.Empty;
|
||||
if (IsHandleCreated)
|
||||
{
|
||||
if (IsTextEmpty) return;
|
||||
string text = Text;
|
||||
int index = text.IndexOf("\t");
|
||||
if (index > 0)
|
||||
|
||||
@@ -190,21 +190,10 @@ namespace AntdUI
|
||||
return result;
|
||||
}
|
||||
|
||||
internal void IKeyPress(KeyPressEventArgs e) => OnKeyPress(e);
|
||||
|
||||
protected override void OnKeyPress(KeyPressEventArgs e)
|
||||
internal void IKeyPress(char keyChar)
|
||||
{
|
||||
if (e.KeyChar < 32)
|
||||
{
|
||||
base.OnKeyPress(e);
|
||||
return;
|
||||
}
|
||||
if (Verify(e.KeyChar, out var change))
|
||||
{
|
||||
EnterText(change ?? e.KeyChar.ToString());
|
||||
base.OnKeyPress(e);
|
||||
}
|
||||
else e.Handled = true;
|
||||
if (keyChar < 32) return;
|
||||
if (Verify(keyChar, out var change)) EnterText(change ?? keyChar.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -551,6 +551,12 @@ namespace AntdUI
|
||||
#region 文本
|
||||
|
||||
internal bool isempty = true;
|
||||
|
||||
/// <summary>
|
||||
/// 文本是否为空
|
||||
/// </summary>
|
||||
public bool IsTextEmpty => isempty;
|
||||
|
||||
string _text = "";
|
||||
[Description("文本"), Category("外观"), DefaultValue("")]
|
||||
[Editor(typeof(System.ComponentModel.Design.MultilineStringEditor), typeof(UITypeEditor))]
|
||||
@@ -1193,6 +1199,12 @@ namespace AntdUI
|
||||
{
|
||||
switch (m.Msg)
|
||||
{
|
||||
case 0x0102:
|
||||
case 0x0109:
|
||||
IKeyPress((char)m.WParam.ToInt32());
|
||||
break;
|
||||
//case 0x0286:
|
||||
// break;
|
||||
case Win32.WM_IME_STARTCOMPOSITION:
|
||||
m_hIMC = Win32.ImmGetContext(Handle);
|
||||
OnImeStartPrivate(m_hIMC);
|
||||
@@ -1230,7 +1242,7 @@ namespace AntdUI
|
||||
}
|
||||
else m.Result = Win32.DLGC_WANTARROWS | Win32.DLGC_WANTCHARS;
|
||||
#endif
|
||||
return;
|
||||
break;
|
||||
}
|
||||
base.WndProc(ref m);
|
||||
}
|
||||
@@ -1492,44 +1504,52 @@ namespace AntdUI
|
||||
|
||||
void OnImeStartPrivate(IntPtr hIMC)
|
||||
{
|
||||
var point = CaretInfo.Rect.Location;
|
||||
point.Offset(0, -scrolly);
|
||||
var CandidateForm = new Win32.CANDIDATEFORM()
|
||||
try
|
||||
{
|
||||
dwStyle = Win32.CFS_CANDIDATEPOS,
|
||||
ptCurrentPos = point,
|
||||
};
|
||||
Win32.ImmSetCandidateWindow(hIMC, ref CandidateForm);
|
||||
var CompositionForm = new Win32.COMPOSITIONFORM()
|
||||
{
|
||||
dwStyle = Win32.CFS_FORCE_POSITION,
|
||||
ptCurrentPos = point,
|
||||
};
|
||||
Win32.ImmSetCompositionWindow(hIMC, ref CompositionForm);
|
||||
var logFont = new Win32.LOGFONT()
|
||||
{
|
||||
lfHeight = CaretInfo.Rect.Height,
|
||||
lfFaceName = Font.Name + "\0"
|
||||
};
|
||||
Win32.ImmSetCompositionFont(hIMC, ref logFont);
|
||||
var point = CaretInfo.Rect.Location;
|
||||
point.Offset(0, -scrolly);
|
||||
var CandidateForm = new Win32.CANDIDATEFORM()
|
||||
{
|
||||
dwStyle = Win32.CFS_CANDIDATEPOS,
|
||||
ptCurrentPos = point,
|
||||
};
|
||||
Win32.ImmSetCandidateWindow(hIMC, ref CandidateForm);
|
||||
var CompositionForm = new Win32.COMPOSITIONFORM()
|
||||
{
|
||||
dwStyle = Win32.CFS_FORCE_POSITION,
|
||||
ptCurrentPos = point,
|
||||
};
|
||||
Win32.ImmSetCompositionWindow(hIMC, ref CompositionForm);
|
||||
var logFont = new Win32.LOGFONT()
|
||||
{
|
||||
lfHeight = CaretInfo.Rect.Height,
|
||||
lfFaceName = Font.Name + "\0"
|
||||
};
|
||||
Win32.ImmSetCompositionFont(hIMC, ref logFont);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
void OnImeResultStrPrivate(IntPtr hIMC, string? strResult)
|
||||
{
|
||||
var CompositionForm = new Win32.COMPOSITIONFORM()
|
||||
try
|
||||
{
|
||||
dwStyle = Win32.CFS_FORCE_POSITION,
|
||||
ptCurrentPos = CaretInfo.Rect.Location
|
||||
};
|
||||
Win32.ImmSetCompositionWindow(hIMC, ref CompositionForm);
|
||||
if (strResult != null && !string.IsNullOrEmpty(strResult))
|
||||
{
|
||||
var chars = new List<string>(strResult.Length);
|
||||
foreach (char key in strResult)
|
||||
var CompositionForm = new Win32.COMPOSITIONFORM()
|
||||
{
|
||||
if (Verify(key, out var change)) chars.Add(change ?? key.ToString());
|
||||
dwStyle = Win32.CFS_FORCE_POSITION,
|
||||
ptCurrentPos = CaretInfo.Rect.Location
|
||||
};
|
||||
Win32.ImmSetCompositionWindow(hIMC, ref CompositionForm);
|
||||
if (strResult != null && !string.IsNullOrEmpty(strResult))
|
||||
{
|
||||
var chars = new List<string>(strResult.Length);
|
||||
foreach (char key in strResult)
|
||||
{
|
||||
if (Verify(key, out var change)) chars.Add(change ?? key.ToString());
|
||||
}
|
||||
if (chars.Count > 0) EnterText(string.Join("", chars));
|
||||
}
|
||||
if (chars.Count > 0) EnterText(string.Join("", chars));
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
protected virtual bool Verify(char key, out string? change)
|
||||
|
||||
@@ -412,12 +412,13 @@ namespace AntdUI
|
||||
|
||||
protected override void OnLostFocus(EventArgs e)
|
||||
{
|
||||
base.OnLostFocus(e);
|
||||
if (IsHandleCreated)
|
||||
{
|
||||
if (IsTextEmpty) return;
|
||||
if (decimal.TryParse(Text, out var _d)) Value = _d;
|
||||
Text = GetNumberText(currentValue);
|
||||
}
|
||||
base.OnLostFocus(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseWheel(MouseEventArgs e)
|
||||
|
||||
@@ -537,4 +537,9 @@ namespace AntdUI
|
||||
public Font? Font { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
public interface ControlEvent
|
||||
{
|
||||
void LoadCompleted();
|
||||
}
|
||||
}
|
||||
@@ -117,12 +117,7 @@ namespace AntdUI
|
||||
BeginInvoke(new Action(() =>
|
||||
{
|
||||
for (int i = 0; i < rows.Length; i++) rows[i].hover = i == i_row;
|
||||
int gap = (int)(Math.Max(_gap, 8) * Config.Dpi), height_real = Helper.GDI(g =>
|
||||
{
|
||||
return g.MeasureString(value?.ToString(), Font, cell.RECT_REAL.Width).Height + gap;
|
||||
}), height2 = cell.RECT_REAL.Height + gap;
|
||||
int height = multiline ? cell.RECT.Height : (height_real > height2 ? height_real : height2);
|
||||
if (cell.RECT_REAL.Height == cell.RECT.Height && height > cell.RECT.Height) height = cell.RECT.Height;
|
||||
int height = EditInputHeight(value, cell);
|
||||
var edit_input = ShowInput(cell, sx, sy, height, multiline, value, _value =>
|
||||
{
|
||||
bool isok_end = true;
|
||||
@@ -169,13 +164,7 @@ namespace AntdUI
|
||||
BeginInvoke(new Action(() =>
|
||||
{
|
||||
for (int i = 0; i < rows.Length; i++) rows[i].hover = i == i_row;
|
||||
|
||||
int gap = (int)(Math.Max(_gap, 8) * Config.Dpi), height_real = Helper.GDI(g =>
|
||||
{
|
||||
return g.MeasureString(value?.ToString(), Font, cell.RECT_REAL.Width).Height + gap;
|
||||
}), height2 = cell.RECT_REAL.Height + gap;
|
||||
int height = multiline ? cell.RECT.Height : (height_real > height2 ? height_real : height2);
|
||||
if (cell.RECT_REAL.Height == cell.RECT.Height && height > cell.RECT.Height) height = cell.RECT.Height;
|
||||
int height = EditInputHeight(value, cell);
|
||||
var edit_input = ShowInput(cell, sx, sy, height, multiline, value, _value =>
|
||||
{
|
||||
bool isok_end = true;
|
||||
@@ -211,6 +200,17 @@ namespace AntdUI
|
||||
}
|
||||
}
|
||||
|
||||
int EditInputHeight(object? value, CELL cell)
|
||||
{
|
||||
if (cell.COLUMN.LineBreak) return cell.RECT.Height;
|
||||
else
|
||||
{
|
||||
int gap = (int)(Math.Max(_gap, 8) * Config.Dpi), height2 = cell.RECT_REAL.Height + gap,
|
||||
height_real = Helper.GDI(g => g.MeasureString(value?.ToString(), Font).Height + gap);
|
||||
return height_real > height2 ? height_real : height2;
|
||||
}
|
||||
}
|
||||
|
||||
bool GetValue(object? value, string _value, out object read)
|
||||
{
|
||||
if (value is int)
|
||||
|
||||
@@ -168,6 +168,7 @@ namespace AntdUI
|
||||
ExpandDrop = false;
|
||||
if (IsHandleCreated)
|
||||
{
|
||||
if (IsTextEmpty) return;
|
||||
if (DateTime.TryParse("1997-1-1 " + Text, out var _d)) Value = new TimeSpan(_d.Hour, _d.Minute, _d.Second);
|
||||
Text = new DateTime(1997, 1, 1, _value.Hours, _value.Minutes, _value.Seconds).ToString(Format);
|
||||
}
|
||||
|
||||
@@ -961,7 +961,7 @@ namespace AntdUI
|
||||
{
|
||||
if (input.input.Focused)
|
||||
{
|
||||
input.input.IKeyPress(e);
|
||||
input.input.IKeyPress(e.KeyChar);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,6 +411,7 @@ namespace AntdUI
|
||||
config.Content.SizeChanged += Content_SizeChanged;
|
||||
tempContent?.Dispose();
|
||||
tempContent = null;
|
||||
if (config.Content is ControlEvent controlEvent) controlEvent.LoadCompleted();
|
||||
}
|
||||
|
||||
bool isok = true;
|
||||
|
||||
@@ -366,6 +366,7 @@ namespace AntdUI
|
||||
base.OnLoad(e);
|
||||
IsLoad = false;
|
||||
LoadCompleted?.Invoke();
|
||||
if (config.Content is ControlEvent controlEvent) controlEvent.LoadCompleted();
|
||||
}
|
||||
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
|
||||
|
||||
@@ -222,6 +222,7 @@ namespace AntdUI
|
||||
form.Location = flocation;
|
||||
PARENT = form;
|
||||
config.OnControlLoad?.Invoke();
|
||||
if (config.Content is ControlEvent controlEvent) controlEvent.LoadCompleted();
|
||||
base.LoadOK();
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,10 @@ namespace AntdUI
|
||||
/// <summary>
|
||||
/// Window 状态改变
|
||||
/// </summary>
|
||||
WINDOW_STATE = 70
|
||||
WINDOW_STATE = 70,
|
||||
/// <summary>
|
||||
/// 自定义
|
||||
/// </summary>
|
||||
DIV = 100
|
||||
}
|
||||
}
|
||||
@@ -93,8 +93,8 @@ namespace AntdUI
|
||||
{
|
||||
var size = new Size((int)(control.Width * dpi), (int)(control.Height * dpi));
|
||||
var point = new Point((int)(control.Left * dpi), (int)(control.Top * dpi));
|
||||
if (!control.MinimumSize.IsEmpty) control.MinimumSize = new Size((int)(control.MinimumSize.Width * dpi), (int)(control.MinimumSize.Height * dpi));
|
||||
if (!control.MaximumSize.IsEmpty) control.MaximumSize = new Size((int)(control.MaximumSize.Width * dpi), (int)(control.MaximumSize.Height * dpi));
|
||||
if (!control.MinimumSize.IsEmpty) control.MinimumSize = new Size((int)(control.MinimumSize.Width * dpi), (int)(control.MinimumSize.Height * dpi));
|
||||
control.Padding = SetPadding(dpi, control.Padding);
|
||||
control.Margin = SetPadding(dpi, control.Margin);
|
||||
control.Size = size;
|
||||
@@ -160,8 +160,8 @@ namespace AntdUI
|
||||
if (point.X < 0 || point.Y < 0) point = form.Location;
|
||||
}
|
||||
if (form.StartPosition == FormStartPosition.CenterScreen) point = new Point(screen.X + (screen.Width - size.Width) / 2, screen.Y + (screen.Height - size.Height) / 2);
|
||||
if (!form.MinimumSize.IsEmpty) form.MinimumSize = new Size((int)(form.MinimumSize.Width * dpi), (int)(form.MinimumSize.Height * dpi));
|
||||
if (!form.MaximumSize.IsEmpty) form.MaximumSize = new Size((int)(form.MaximumSize.Width * dpi), (int)(form.MaximumSize.Height * dpi));
|
||||
if (!form.MinimumSize.IsEmpty) form.MinimumSize = new Size((int)(form.MinimumSize.Width * dpi), (int)(form.MinimumSize.Height * dpi));
|
||||
form.Padding = SetPadding(dpi, form.Padding);
|
||||
form.Margin = SetPadding(dpi, form.Margin);
|
||||
|
||||
|
||||
@@ -228,7 +228,8 @@ namespace AntdUI
|
||||
{
|
||||
if (hIMC == IntPtr.Zero) return null;
|
||||
int nLen = ImmGetCompositionString(hIMC, dwIndex, m_byString, m_byString.Length);
|
||||
return Encoding.Unicode.GetString(m_byString, 0, nLen);
|
||||
if (nLen > 0) return Encoding.Unicode.GetString(m_byString, 0, nLen);
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user