Skip to content

Commit d45f711

Browse files
committed
.net upgraded to 4.8;
icon small text position fix
1 parent 8443156 commit d45f711

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

GUI/SensorNotifyIcon.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public SensorNotifyIcon(SystemTray sensorSystemTray, ISensor sensor,
9595
}
9696

9797
font = new Font(family, baseSize * width / 16.0f, GraphicsUnit.Pixel);
98-
smallFont = new Font(family, 0.75f * baseSize * width / 16.0f, GraphicsUnit.Pixel);
98+
smallFont = new Font(family, 0.7f * baseSize * width / 16.0f, GraphicsUnit.Pixel);
9999

100100
bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
101101
graphics = Graphics.FromImage(bitmap);
@@ -209,19 +209,22 @@ private Icon CreateTransparentIcon() {
209209
graphics.Clear(defaultBackColor);
210210
}
211211

212-
var textShift = bitmap.Width / 8 - 1; //todo: tested for 16 & 32 only
213212
if (small) {
214213
if (text[1] == '.' || text[1] == ',') {
215214
var bigPart = text.Substring(0, 1);
216215
var smallPart = text.Substring(1);
217-
TextRenderer.DrawText(graphics, bigPart, font, new Point(-4, -2), color, defaultBackColor);
218-
TextRenderer.DrawText(graphics, smallPart, smallFont, new Point(4 * textShift, 1 * textShift), color, defaultBackColor);
216+
var bigSize = TextRenderer.MeasureText(bigPart, font);
217+
var smallSize = TextRenderer.MeasureText(smallPart, smallFont);
218+
TextRenderer.DrawText(graphics, bigPart, font, new Point(-4, (bitmap.Height - bigSize.Height) / 2), color, defaultBackColor);
219+
TextRenderer.DrawText(graphics, smallPart, smallFont, new Point(4 * (bitmap.Width / 8 - 1), bitmap.Height - smallSize.Height), color, defaultBackColor);
219220
} else {
220-
TextRenderer.DrawText(graphics, text, smallFont, new Point(-2 * textShift, 2 * textShift), color, defaultBackColor);
221+
var size = TextRenderer.MeasureText(text, smallFont);
222+
TextRenderer.DrawText(graphics, text, smallFont, new Point((bitmap.Width - size.Width) / 2, (bitmap.Height - size.Height) / 2), color, defaultBackColor);
221223
}
222224
}
223225
else {
224-
TextRenderer.DrawText(graphics, text, font, new Point(-2 * textShift, -1 * textShift), color, defaultBackColor);
226+
var size = TextRenderer.MeasureText(text, font);
227+
TextRenderer.DrawText(graphics, text, font, new Point((bitmap.Width - size.Width) / 2, (bitmap.Height - size.Height) / 2), color, defaultBackColor);
225228
}
226229

227230
var data = bitmap.LockBits(

OpenHardwareMonitor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<OutputType>WinExe</OutputType>
1010
<NoStandardLibraries>false</NoStandardLibraries>
1111
<AssemblyName>OpenHardwareMonitor</AssemblyName>
12-
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<RootNamespace>OpenHardwareMonitor</RootNamespace>
1515
<ApplicationIcon>Resources\icon.ico</ApplicationIcon>

0 commit comments

Comments
 (0)