mirror of
https://github.com/openhardwaremonitor/openhardwaremonitor
synced 2025-08-22 09:57:20 +00:00
Small corrections to improve the DPI awareness (display scaling).
This commit is contained in:
parent
c623d6bb22
commit
ad58051a92
4
GUI/AboutBox.Designer.cs
generated
4
GUI/AboutBox.Designer.cs
generated
@ -62,7 +62,7 @@ namespace OpenHardwareMonitor.GUI {
|
||||
this.pictureBox1.Location = new System.Drawing.Point(10, 11);
|
||||
this.pictureBox1.Name = "pictureBox1";
|
||||
this.pictureBox1.Size = new System.Drawing.Size(48, 48);
|
||||
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
|
||||
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
|
||||
this.pictureBox1.TabIndex = 1;
|
||||
this.pictureBox1.TabStop = false;
|
||||
//
|
||||
@ -169,4 +169,4 @@ namespace OpenHardwareMonitor.GUI {
|
||||
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
|
||||
private System.Windows.Forms.LinkLabel licenseLinkLabel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
54
GUI/DpiHelper.cs
Normal file
54
GUI/DpiHelper.cs
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla Public
|
||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
Copyright (C) 2020 Michael Möller <mmoeller@openhardwaremonitor.org>
|
||||
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenHardwareMonitor.GUI {
|
||||
|
||||
public static class DpiHelper {
|
||||
public const double LogicalDpi = 96.0;
|
||||
|
||||
private static double deviceDpi;
|
||||
public static double DeviceDpi {
|
||||
get {
|
||||
if (deviceDpi == 0.0) {
|
||||
try {
|
||||
using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) {
|
||||
deviceDpi = g.DpiX;
|
||||
}
|
||||
} catch { }
|
||||
if (deviceDpi == 0.0)
|
||||
deviceDpi = LogicalDpi;
|
||||
}
|
||||
return deviceDpi;
|
||||
}
|
||||
}
|
||||
|
||||
private static double logicalToDeviceUnitsScalingFactor;
|
||||
public static double LogicalToDeviceUnitsScalingFactor {
|
||||
get {
|
||||
if (logicalToDeviceUnitsScalingFactor == 0.0) {
|
||||
logicalToDeviceUnitsScalingFactor = DeviceDpi / LogicalDpi;
|
||||
}
|
||||
return logicalToDeviceUnitsScalingFactor;
|
||||
}
|
||||
}
|
||||
|
||||
public static int LogicalToDeviceUnits(int value) {
|
||||
return (int)Math.Round(LogicalToDeviceUnitsScalingFactor * (double)value);
|
||||
}
|
||||
|
||||
public static Size LogicalToDeviceUnits(Size logicalSize) {
|
||||
return new Size(LogicalToDeviceUnits(logicalSize.Width),
|
||||
LogicalToDeviceUnits(logicalSize.Height));
|
||||
}
|
||||
}
|
||||
}
|
11
GUI/MainForm.Designer.cs
generated
11
GUI/MainForm.Designer.cs
generated
@ -119,29 +119,26 @@ namespace OpenHardwareMonitor.GUI {
|
||||
//
|
||||
this.sensor.Header = "Sensor";
|
||||
this.sensor.SortOrder = System.Windows.Forms.SortOrder.None;
|
||||
this.sensor.TooltipText = null;
|
||||
this.sensor.Width = 250;
|
||||
this.sensor.TooltipText = null;
|
||||
//
|
||||
// value
|
||||
//
|
||||
this.value.Header = "Value";
|
||||
this.value.SortOrder = System.Windows.Forms.SortOrder.None;
|
||||
this.value.TooltipText = null;
|
||||
this.value.Width = 100;
|
||||
this.value.TooltipText = null;
|
||||
//
|
||||
// min
|
||||
//
|
||||
this.min.Header = "Min";
|
||||
this.min.SortOrder = System.Windows.Forms.SortOrder.None;
|
||||
this.min.TooltipText = null;
|
||||
this.min.Width = 100;
|
||||
this.min.TooltipText = null;
|
||||
//
|
||||
// max
|
||||
//
|
||||
this.max.Header = "Max";
|
||||
this.max.SortOrder = System.Windows.Forms.SortOrder.None;
|
||||
this.max.TooltipText = null;
|
||||
this.max.Width = 100;
|
||||
|
||||
//
|
||||
// nodeImage
|
||||
//
|
||||
|
@ -112,8 +112,14 @@ namespace OpenHardwareMonitor.GUI {
|
||||
nodeTextBoxMax.DrawText += nodeTextBoxText_DrawText;
|
||||
nodeTextBoxText.EditorShowing += nodeTextBoxText_EditorShowing;
|
||||
|
||||
this.sensor.Width = DpiHelper.LogicalToDeviceUnits(250);
|
||||
this.value.Width = DpiHelper.LogicalToDeviceUnits(100);
|
||||
this.min.Width = DpiHelper.LogicalToDeviceUnits(100);
|
||||
this.max.Width = DpiHelper.LogicalToDeviceUnits(100);
|
||||
|
||||
foreach (TreeColumn column in treeView.Columns)
|
||||
column.Width = Math.Max(20, Math.Min(400,
|
||||
column.Width = Math.Max(DpiHelper.LogicalToDeviceUnits(20), Math.Min(
|
||||
DpiHelper.LogicalToDeviceUnits(400),
|
||||
settings.GetValue("treeView.Columns." + column.Header + ".Width",
|
||||
column.Width)));
|
||||
|
||||
@ -131,7 +137,8 @@ namespace OpenHardwareMonitor.GUI {
|
||||
systemTray.ExitCommand += exitClick;
|
||||
|
||||
if (Hardware.OperatingSystem.IsUnix) { // Unix
|
||||
treeView.RowHeight = Math.Max(treeView.RowHeight, 18);
|
||||
treeView.RowHeight = Math.Max(treeView.RowHeight,
|
||||
DpiHelper.LogicalToDeviceUnits(18));
|
||||
splitContainer.BorderStyle = BorderStyle.None;
|
||||
splitContainer.Border3DStyle = Border3DStyle.Adjust;
|
||||
splitContainer.SplitterWidth = 4;
|
||||
@ -142,7 +149,9 @@ namespace OpenHardwareMonitor.GUI {
|
||||
minTrayMenuItem.Visible = false;
|
||||
startMinMenuItem.Visible = false;
|
||||
} else { // Windows
|
||||
treeView.RowHeight = Math.Max(treeView.Font.Height + 1, 18);
|
||||
treeView.RowHeight = Math.Max(treeView.Font.Height +
|
||||
DpiHelper.LogicalToDeviceUnits(1),
|
||||
DpiHelper.LogicalToDeviceUnits(18));
|
||||
|
||||
gadget = new SensorGadget(computer, settings, unitManager);
|
||||
gadget.HideShowCommand += hideShowClick;
|
||||
@ -617,8 +626,10 @@ namespace OpenHardwareMonitor.GUI {
|
||||
Rectangle newBounds = new Rectangle {
|
||||
X = settings.GetValue("mainForm.Location.X", Location.X),
|
||||
Y = settings.GetValue("mainForm.Location.Y", Location.Y),
|
||||
Width = settings.GetValue("mainForm.Width", 470),
|
||||
Height = settings.GetValue("mainForm.Height", 640)
|
||||
Width = settings.GetValue("mainForm.Width",
|
||||
DpiHelper.LogicalToDeviceUnits(470)),
|
||||
Height = settings.GetValue("mainForm.Height",
|
||||
DpiHelper.LogicalToDeviceUnits(640))
|
||||
};
|
||||
|
||||
Rectangle fullWorkingArea = new Rectangle(int.MaxValue, int.MaxValue,
|
||||
|
@ -69,6 +69,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="GUI\DpiHelper.cs" />
|
||||
<Compile Include="GUI\GadgetWindow.cs" />
|
||||
<Compile Include="GUI\Gadget.cs" />
|
||||
<Compile Include="GUI\HardwareTypeImage.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user