-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCurrentDPILabel.cs
38 lines (31 loc) · 915 Bytes
/
CurrentDPILabel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace PerMonitorDemo
{
public partial class CurrentDPILabel : Label
{
public CurrentDPILabel()
{
DpiChangedAfterParent += CurrentDPILabel_DpiChangedAfterParent;
HandleCreated += CurrentDPILabel_HandleCreated;
}
[DefaultValue(false)]
public override bool AutoSize {
get { return base.AutoSize; }
set { base.AutoSize = value; }
}
private void CurrentDPILabel_HandleCreated(object sender, EventArgs e)
{
SetText();
}
private void CurrentDPILabel_DpiChangedAfterParent(object sender, EventArgs e)
{
SetText();
}
private void SetText()
{
Text = $"Current scaling is {(int)Math.Round((DeviceDpi / 96.0) * 100)}%";
}
}
}