mirror of
https://github.com/openhardwaremonitor/openhardwaremonitor
synced 2025-08-22 18:07:09 +00:00
Small corrections to improve the DPI awareness (display scaling).
This commit is contained in:
parent
c623d6bb22
commit
ad58051a92
2
GUI/AboutBox.Designer.cs
generated
2
GUI/AboutBox.Designer.cs
generated
@ -62,7 +62,7 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
this.pictureBox1.Location = new System.Drawing.Point(10, 11);
|
this.pictureBox1.Location = new System.Drawing.Point(10, 11);
|
||||||
this.pictureBox1.Name = "pictureBox1";
|
this.pictureBox1.Name = "pictureBox1";
|
||||||
this.pictureBox1.Size = new System.Drawing.Size(48, 48);
|
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.TabIndex = 1;
|
||||||
this.pictureBox1.TabStop = false;
|
this.pictureBox1.TabStop = false;
|
||||||
//
|
//
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
5
GUI/MainForm.Designer.cs
generated
5
GUI/MainForm.Designer.cs
generated
@ -120,28 +120,25 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
this.sensor.Header = "Sensor";
|
this.sensor.Header = "Sensor";
|
||||||
this.sensor.SortOrder = System.Windows.Forms.SortOrder.None;
|
this.sensor.SortOrder = System.Windows.Forms.SortOrder.None;
|
||||||
this.sensor.TooltipText = null;
|
this.sensor.TooltipText = null;
|
||||||
this.sensor.Width = 250;
|
|
||||||
//
|
//
|
||||||
// value
|
// value
|
||||||
//
|
//
|
||||||
this.value.Header = "Value";
|
this.value.Header = "Value";
|
||||||
this.value.SortOrder = System.Windows.Forms.SortOrder.None;
|
this.value.SortOrder = System.Windows.Forms.SortOrder.None;
|
||||||
this.value.TooltipText = null;
|
this.value.TooltipText = null;
|
||||||
this.value.Width = 100;
|
|
||||||
//
|
//
|
||||||
// min
|
// min
|
||||||
//
|
//
|
||||||
this.min.Header = "Min";
|
this.min.Header = "Min";
|
||||||
this.min.SortOrder = System.Windows.Forms.SortOrder.None;
|
this.min.SortOrder = System.Windows.Forms.SortOrder.None;
|
||||||
this.min.TooltipText = null;
|
this.min.TooltipText = null;
|
||||||
this.min.Width = 100;
|
|
||||||
//
|
//
|
||||||
// max
|
// max
|
||||||
//
|
//
|
||||||
this.max.Header = "Max";
|
this.max.Header = "Max";
|
||||||
this.max.SortOrder = System.Windows.Forms.SortOrder.None;
|
this.max.SortOrder = System.Windows.Forms.SortOrder.None;
|
||||||
this.max.TooltipText = null;
|
this.max.TooltipText = null;
|
||||||
this.max.Width = 100;
|
|
||||||
//
|
//
|
||||||
// nodeImage
|
// nodeImage
|
||||||
//
|
//
|
||||||
|
@ -112,8 +112,14 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
nodeTextBoxMax.DrawText += nodeTextBoxText_DrawText;
|
nodeTextBoxMax.DrawText += nodeTextBoxText_DrawText;
|
||||||
nodeTextBoxText.EditorShowing += nodeTextBoxText_EditorShowing;
|
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)
|
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",
|
settings.GetValue("treeView.Columns." + column.Header + ".Width",
|
||||||
column.Width)));
|
column.Width)));
|
||||||
|
|
||||||
@ -131,7 +137,8 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
systemTray.ExitCommand += exitClick;
|
systemTray.ExitCommand += exitClick;
|
||||||
|
|
||||||
if (Hardware.OperatingSystem.IsUnix) { // Unix
|
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.BorderStyle = BorderStyle.None;
|
||||||
splitContainer.Border3DStyle = Border3DStyle.Adjust;
|
splitContainer.Border3DStyle = Border3DStyle.Adjust;
|
||||||
splitContainer.SplitterWidth = 4;
|
splitContainer.SplitterWidth = 4;
|
||||||
@ -142,7 +149,9 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
minTrayMenuItem.Visible = false;
|
minTrayMenuItem.Visible = false;
|
||||||
startMinMenuItem.Visible = false;
|
startMinMenuItem.Visible = false;
|
||||||
} else { // Windows
|
} 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 = new SensorGadget(computer, settings, unitManager);
|
||||||
gadget.HideShowCommand += hideShowClick;
|
gadget.HideShowCommand += hideShowClick;
|
||||||
@ -617,8 +626,10 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
Rectangle newBounds = new Rectangle {
|
Rectangle newBounds = new Rectangle {
|
||||||
X = settings.GetValue("mainForm.Location.X", Location.X),
|
X = settings.GetValue("mainForm.Location.X", Location.X),
|
||||||
Y = settings.GetValue("mainForm.Location.Y", Location.Y),
|
Y = settings.GetValue("mainForm.Location.Y", Location.Y),
|
||||||
Width = settings.GetValue("mainForm.Width", 470),
|
Width = settings.GetValue("mainForm.Width",
|
||||||
Height = settings.GetValue("mainForm.Height", 640)
|
DpiHelper.LogicalToDeviceUnits(470)),
|
||||||
|
Height = settings.GetValue("mainForm.Height",
|
||||||
|
DpiHelper.LogicalToDeviceUnits(640))
|
||||||
};
|
};
|
||||||
|
|
||||||
Rectangle fullWorkingArea = new Rectangle(int.MaxValue, int.MaxValue,
|
Rectangle fullWorkingArea = new Rectangle(int.MaxValue, int.MaxValue,
|
||||||
|
@ -69,6 +69,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="GUI\DpiHelper.cs" />
|
||||||
<Compile Include="GUI\GadgetWindow.cs" />
|
<Compile Include="GUI\GadgetWindow.cs" />
|
||||||
<Compile Include="GUI\Gadget.cs" />
|
<Compile Include="GUI\Gadget.cs" />
|
||||||
<Compile Include="GUI\HardwareTypeImage.cs" />
|
<Compile Include="GUI\HardwareTypeImage.cs" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user