* 重构全局字体设置逻辑,以期可以在程序运行时设置全局字体
This commit is contained in:
parent
83caee295e
commit
82f4074ba5
@ -642,7 +642,7 @@ namespace Sunny.UI
|
||||
NavBarMenu.Style = UIStyles.Style;
|
||||
NavBarMenu.Items.Clear();
|
||||
NavBarMenu.ImageList = ImageList;
|
||||
NavBarMenu.Font = DropMenuFont.SetDPIScaleFont(DropMenuFont.Size);
|
||||
NavBarMenu.Font = DropMenuFont;
|
||||
foreach (TreeNode node in Nodes[SelectedIndex].Nodes)
|
||||
{
|
||||
ToolStripMenuItem item = new ToolStripMenuItem(node.Text) { Tag = node };
|
||||
|
@ -35,8 +35,6 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
#pragma warning disable 1591
|
||||
|
||||
namespace Sunny.UI
|
||||
{
|
||||
public sealed partial class UINotifier : Form
|
||||
@ -108,7 +106,7 @@ namespace Sunny.UI
|
||||
InApplication = insideMe;
|
||||
|
||||
InitializeComponent();
|
||||
if (Notes.Count == 0)
|
||||
if (Notes.IsEmpty)
|
||||
ID = 1;
|
||||
else
|
||||
ID = (short)(Notes.Keys.Max() + 1); // Set the Note ID
|
||||
|
@ -29,22 +29,24 @@ namespace Sunny.UI
|
||||
{
|
||||
private static float dpiScale = -1;
|
||||
|
||||
public static float DPIScale()
|
||||
public static float DPIScale() => UIStyles.GlobalFont ? SystemDPIScale * 100.0f / UIStyles.GlobalFontScale : SystemDPIScale;
|
||||
|
||||
private static float SystemDPIScale
|
||||
{
|
||||
if (dpiScale < 0)
|
||||
get
|
||||
{
|
||||
using Bitmap bmp = new Bitmap(1, 1);
|
||||
using Graphics g = bmp.Graphics();
|
||||
dpiScale = g.DpiX / 96.0f;
|
||||
if (dpiScale < 0)
|
||||
{
|
||||
using Bitmap bmp = new Bitmap(1, 1);
|
||||
using Graphics g = bmp.Graphics();
|
||||
dpiScale = g.DpiX / 96.0f;
|
||||
}
|
||||
|
||||
return dpiScale;
|
||||
}
|
||||
|
||||
return UIStyles.GlobalFont ? dpiScale * 100.0f / UIStyles.GlobalFontScale : dpiScale;
|
||||
}
|
||||
|
||||
public static bool NeedSetDPIFont()
|
||||
{
|
||||
return UIStyles.DPIScale && (DPIScale() > 1 || UIStyles.GlobalFont);
|
||||
}
|
||||
public static bool NeedSetDPIFont() => UIStyles.DPIScale && (SystemDPIScale > 1 || UIStyles.GlobalFont);
|
||||
|
||||
internal static Font DPIScaleFont(this Font font, float fontSize)
|
||||
{
|
||||
@ -78,21 +80,22 @@ namespace Sunny.UI
|
||||
internal static List<IStyleInterface> GetAllDPIScaleControls(this Control control)
|
||||
{
|
||||
var list = new List<IStyleInterface>();
|
||||
foreach (Control con in control.Controls)
|
||||
foreach (Control ctrl in control.Controls)
|
||||
{
|
||||
if (con is IStyleInterface ctrl) list.Add(ctrl);
|
||||
if (ctrl is IStyleInterface istyleCtrl) list.Add(istyleCtrl);
|
||||
|
||||
if (con is UITextBox) continue;
|
||||
if (con is UIDropControl) continue;
|
||||
if (con is UIListBox) continue;
|
||||
if (con is UIImageListBox) continue;
|
||||
if (con is UIPagination) continue;
|
||||
if (con is UIRichTextBox) continue;
|
||||
if (con is UITreeView) continue;
|
||||
if (ctrl is UITextBox) continue;
|
||||
if (ctrl is UIDropControl) continue;
|
||||
if (ctrl is UIListBox) continue;
|
||||
if (ctrl is UIImageListBox) continue;
|
||||
if (ctrl is UIPagination) continue;
|
||||
if (ctrl is UIRichTextBox) continue;
|
||||
if (ctrl is UITreeView) continue;
|
||||
if (ctrl is UITransfer) continue;
|
||||
|
||||
if (con.Controls.Count > 0)
|
||||
if (ctrl.Controls.Count > 0)
|
||||
{
|
||||
list.AddRange(GetAllDPIScaleControls(con));
|
||||
list.AddRange(GetAllDPIScaleControls(ctrl));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user