* UIStyle: 修改DPI自适应缩放
This commit is contained in:
parent
45fad139bc
commit
ebfef9c105
Binary file not shown.
Binary file not shown.
@ -329,6 +329,12 @@ namespace Sunny.UI
|
|||||||
control.Font.Style, control.Font.Unit, control.Font.GdiCharSet);
|
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)
|
public static void SetDPIScaleFont(this Control control)
|
||||||
{
|
{
|
||||||
if (!control.DPIScale().Equals(1))
|
if (!control.DPIScale().Equals(1))
|
||||||
@ -490,7 +496,6 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
private static bool GetChildNodeCheckedState(TreeNode node)
|
private static bool GetChildNodeCheckedState(TreeNode node)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (node.Nodes.Count > 0)
|
if (node.Nodes.Count > 0)
|
||||||
{
|
{
|
||||||
var count = node.Nodes.Cast<TreeNode>().Where(n => n.Checked).ToList().Count;
|
var count = node.Nodes.Cast<TreeNode>().Where(n => n.Checked).ToList().Count;
|
||||||
@ -505,8 +510,6 @@ namespace Sunny.UI
|
|||||||
return GetChildNodeCheckedState(nd);
|
return GetChildNodeCheckedState(nd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,12 @@ namespace Sunny.UI
|
|||||||
if (!IsScaled && UIStyles.DPIScale)
|
if (!IsScaled && UIStyles.DPIScale)
|
||||||
{
|
{
|
||||||
this.SetDPIScaleFont();
|
this.SetDPIScaleFont();
|
||||||
|
|
||||||
|
if (!this.DPIScale().Equals(1))
|
||||||
|
{
|
||||||
|
this.TitleFont = this.DPIScaleFont(this.TitleFont);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (Control control in this.GetAllDPIScaleControls())
|
foreach (Control control in this.GetAllDPIScaleControls())
|
||||||
{
|
{
|
||||||
control.SetDPIScaleFont();
|
control.SetDPIScaleFont();
|
||||||
@ -444,7 +450,6 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Rectangle ControlBoxRect;
|
private Rectangle ControlBoxRect;
|
||||||
|
|
||||||
private Rectangle MaximizeBoxRect;
|
private Rectangle MaximizeBoxRect;
|
||||||
@ -1509,12 +1514,14 @@ namespace Sunny.UI
|
|||||||
case Win32.User.WM_ERASEBKGND:
|
case Win32.User.WM_ERASEBKGND:
|
||||||
m.Result = IntPtr.Zero;
|
m.Result = IntPtr.Zero;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Win32.User.WM_HOTKEY:
|
case Win32.User.WM_HOTKEY:
|
||||||
int hotKeyId = (int)(m.WParam);
|
int hotKeyId = (int)(m.WParam);
|
||||||
if (hotKeys.ContainsKey(hotKeyId))
|
if (hotKeys.ContainsKey(hotKeyId))
|
||||||
HotKeyEventHandler?.Invoke(this, new HotKeyEventArgs(hotKeys[hotKeyId], DateTime.Now));
|
HotKeyEventHandler?.Invoke(this, new HotKeyEventArgs(hotKeys[hotKeyId], DateTime.Now));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
base.WndProc(ref m);
|
base.WndProc(ref m);
|
||||||
break;
|
break;
|
||||||
@ -1522,7 +1529,7 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
if (m.Msg == Win32.User.WM_NCHITTEST && ShowDragStretch && WindowState == FormWindowState.Normal)
|
if (m.Msg == Win32.User.WM_NCHITTEST && ShowDragStretch && WindowState == FormWindowState.Normal)
|
||||||
{
|
{
|
||||||
//Point vPoint = new Point((int)m.LParam & 0xFFFF, (int)m.LParam >> 16 & 0xFFFF);
|
//Point vPoint = new Point((int)m.LParam & 0xFFFF, (int)m.LParam >> 16 & 0xFFFF);
|
||||||
Point vPoint = new Point(MousePosition.X, MousePosition.Y);//修正有分屏后,调整窗体大小时鼠标显示左右箭头问题
|
Point vPoint = new Point(MousePosition.X, MousePosition.Y);//修正有分屏后,调整窗体大小时鼠标显示左右箭头问题
|
||||||
vPoint = PointToClient(vPoint);
|
vPoint = PointToClient(vPoint);
|
||||||
int dragSize = 5;
|
int dragSize = 5;
|
||||||
@ -1842,7 +1849,7 @@ namespace Sunny.UI
|
|||||||
UINotifierHelper.ShowNotifier(desc, UINotifierType.ERROR, UILocalize.ErrorTitle, isDialog, timeout);
|
UINotifierHelper.ShowNotifier(desc, UINotifierType.ERROR, UILocalize.ErrorTitle, isDialog, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion 一些辅助窗口
|
||||||
|
|
||||||
#region IFrame实现
|
#region IFrame实现
|
||||||
|
|
||||||
@ -1889,7 +1896,6 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
public virtual void Feedback(object sender, int pageIndex, params object[] objects)
|
public virtual void Feedback(object sender, int pageIndex, params object[] objects)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion IFrame实现
|
#endregion IFrame实现
|
||||||
|
@ -30,6 +30,7 @@ using System.Diagnostics;
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Design;
|
using System.Drawing.Design;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||||
|
|
||||||
namespace Sunny.UI
|
namespace Sunny.UI
|
||||||
{
|
{
|
||||||
@ -76,6 +77,11 @@ namespace Sunny.UI
|
|||||||
if (!IsScaled)
|
if (!IsScaled)
|
||||||
{
|
{
|
||||||
this.SetDPIScaleFont();
|
this.SetDPIScaleFont();
|
||||||
|
if (!this.DPIScale().Equals(1))
|
||||||
|
{
|
||||||
|
this.TitleFont = this.DPIScaleFont(this.TitleFont);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (Control control in this.GetAllDPIScaleControls())
|
foreach (Control control in this.GetAllDPIScaleControls())
|
||||||
{
|
{
|
||||||
control.SetDPIScaleFont();
|
control.SetDPIScaleFont();
|
||||||
@ -145,7 +151,6 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
protected virtual void SymbolChange()
|
protected virtual void SymbolChange()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Browsable(false)]
|
[Browsable(false)]
|
||||||
@ -239,6 +244,7 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler Initialize;
|
public event EventHandler Initialize;
|
||||||
|
|
||||||
public event EventHandler Finalize;
|
public event EventHandler Finalize;
|
||||||
|
|
||||||
protected override void OnControlAdded(ControlEventArgs e)
|
protected override void OnControlAdded(ControlEventArgs e)
|
||||||
@ -533,7 +539,6 @@ namespace Sunny.UI
|
|||||||
InControlBox = inControlBox;
|
InControlBox = inControlBox;
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -574,7 +579,6 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected override void OnTextChanged(EventArgs e)
|
protected override void OnTextChanged(EventArgs e)
|
||||||
{
|
{
|
||||||
base.OnTextChanged(e);
|
base.OnTextChanged(e);
|
||||||
@ -584,12 +588,10 @@ namespace Sunny.UI
|
|||||||
private void CalcSystemBoxPos()
|
private void CalcSystemBoxPos()
|
||||||
{
|
{
|
||||||
ControlBoxRect = new Rectangle(Width - 6 - 28, titleHeight / 2 - 14, 28, 28);
|
ControlBoxRect = new Rectangle(Width - 6 - 28, titleHeight / 2 - 14, 28, 28);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Rectangle ControlBoxRect;
|
private Rectangle ControlBoxRect;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否显示窗体的控制按钮
|
/// 是否显示窗体的控制按钮
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -894,6 +896,6 @@ namespace Sunny.UI
|
|||||||
UINotifierHelper.ShowNotifier(desc, UINotifierType.ERROR, UILocalize.ErrorTitle, isDialog, timeout);
|
UINotifierHelper.ShowNotifier(desc, UINotifierType.ERROR, UILocalize.ErrorTitle, isDialog, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion 一些辅助窗口
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user