I have a small C# program, HelloCs.cs, like this:
using System;
using System.Drawing;
using System.Windows.Forms;
class HelloWorld: Form
{
public static void Main()
{
Application.Run(new HelloWorld());
}
public HelloWorld()
{
Text = "Hello World";
BackColor = Color.White;
}
protected override void OnPaint(PaintEventArgs pea)
{
Graphics grfx = pea.Graphics;
this.Width = 200;
this.Height = 100;
grfx.DrawString(
$"({this.Width} , {this.Height}) Hello, Windows Forms!",
Font, Brushes.Black, 0, 0);
base.OnPaint(pea);
}
}
== CASE 1.0 ==
When run on a default Windows 7 system. It shows like this, nothing special:
The window width & height is 200 & 100 respectively.
== CASE 1.5 ==
When I set system DPI scaling to 150% (and restart OS), C# program still reports window width & height as before, BUT, the window's actual on-screen size(pixel count) becomes 300 and 150. That means, Windows system has apply so-called bitmap-scaling on my window.
Then my question is: How do I know(in my own program, or with an HWND handle), whether the system has applied bitmap-scaling to the window, and what is the scaling factor.
On Window 10, things becomes more complicated, because Windows 10 may apply different scaling factor to different HWND, according to the HWND's current residing monitor.
I hope to get an answer applicable to Both Windows 7 and 10.