* UIStyle: 修改DPI自适应缩放

This commit is contained in:
Sunny 2021-11-17 23:46:56 +08:00
parent 45fad139bc
commit ebfef9c105
5 changed files with 26 additions and 15 deletions

Binary file not shown.

Binary file not shown.

View File

@ -329,6 +329,12 @@ namespace Sunny.UI
control.Font.Style, control.Font.Unit, control.Font.GdiCharSet);
}
public static Font DPIScaleFont(this Control control, Font font)
{
return new Font(font.FontFamily, font.Size / control.DPIScale(),
font.Style, font.Unit, font.GdiCharSet);
}
public static void SetDPIScaleFont(this Control control)
{
if (!control.DPIScale().Equals(1))
@ -490,7 +496,6 @@ namespace Sunny.UI
private static bool GetChildNodeCheckedState(TreeNode node)
{
if (node.Nodes.Count > 0)
{
var count = node.Nodes.Cast<TreeNode>().Where(n => n.Checked).ToList().Count;
@ -505,8 +510,6 @@ namespace Sunny.UI
return GetChildNodeCheckedState(nd);
}
}
}
return false;
}

View File

@ -79,6 +79,12 @@ namespace Sunny.UI
if (!IsScaled && UIStyles.DPIScale)
{
this.SetDPIScaleFont();
if (!this.DPIScale().Equals(1))
{
this.TitleFont = this.DPIScaleFont(this.TitleFont);
}
foreach (Control control in this.GetAllDPIScaleControls())
{
control.SetDPIScaleFont();
@ -444,7 +450,6 @@ namespace Sunny.UI
}
}
private Rectangle ControlBoxRect;
private Rectangle MaximizeBoxRect;
@ -1509,12 +1514,14 @@ namespace Sunny.UI
case Win32.User.WM_ERASEBKGND:
m.Result = IntPtr.Zero;
break;
case Win32.User.WM_HOTKEY:
int hotKeyId = (int)(m.WParam);
if (hotKeys.ContainsKey(hotKeyId))
HotKeyEventHandler?.Invoke(this, new HotKeyEventArgs(hotKeys[hotKeyId], DateTime.Now));
break;
default:
base.WndProc(ref m);
break;
@ -1842,7 +1849,7 @@ namespace Sunny.UI
UINotifierHelper.ShowNotifier(desc, UINotifierType.ERROR, UILocalize.ErrorTitle, isDialog, timeout);
}
#endregion
#endregion
#region IFrame实现
@ -1889,7 +1896,6 @@ namespace Sunny.UI
public virtual void Feedback(object sender, int pageIndex, params object[] objects)
{
}
#endregion IFrame实现

View File

@ -30,6 +30,7 @@ using System.Diagnostics;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace Sunny.UI
{
@ -76,6 +77,11 @@ namespace Sunny.UI
if (!IsScaled)
{
this.SetDPIScaleFont();
if (!this.DPIScale().Equals(1))
{
this.TitleFont = this.DPIScaleFont(this.TitleFont);
}
foreach (Control control in this.GetAllDPIScaleControls())
{
control.SetDPIScaleFont();
@ -145,7 +151,6 @@ namespace Sunny.UI
protected virtual void SymbolChange()
{
}
[Browsable(false)]
@ -239,6 +244,7 @@ namespace Sunny.UI
}
public event EventHandler Initialize;
public event EventHandler Finalize;
protected override void OnControlAdded(ControlEventArgs e)
@ -533,7 +539,6 @@ namespace Sunny.UI
InControlBox = inControlBox;
Invalidate();
}
}
}
@ -574,7 +579,6 @@ namespace Sunny.UI
}
}
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged(e);
@ -584,12 +588,10 @@ namespace Sunny.UI
private void CalcSystemBoxPos()
{
ControlBoxRect = new Rectangle(Width - 6 - 28, titleHeight / 2 - 14, 28, 28);
}
private Rectangle ControlBoxRect;
/// <summary>
/// 是否显示窗体的控制按钮
/// </summary>
@ -894,6 +896,6 @@ namespace Sunny.UI
UINotifierHelper.ShowNotifier(desc, UINotifierType.ERROR, UILocalize.ErrorTitle, isDialog, timeout);
}
#endregion
#endregion
}
}