Graphics.DpiX / Graphics.DpiY always returns the primary monitor's DPI even though the application window is dragged to the extended monitor

Viewed 51

I’m running my application in an extended monitor setup.

I need to choose between some images from the resources based on the current DPI. For that I’m using the below given code.

private void getDPIButton1_Click(object sender, EventArgs e)
{
    var graphics = this.CreateGraphics();

    var x = graphics.DpiX;
    var y = graphics.DpiY;

    graphics.Dispose();
}

But the problem is, this code always returns the DPI of the primary monitor.

Replication :

  1. At first the sample is launched in the primary monitor.
  2. When I check the DPI it returns primary monitor’s dpi and it is the expected one.
  3. Now I drag the window to the extended monitor with higher dpi.
  4. If I check the DPI with same code, it again returns the DPI of the primary monitor. But I need to get the DPI of the extended monitor in which the window is shown now.

Please let me know if it is an issue or is there any other way to get the DPI of the extended monitor?

Thanks in advance.

0 Answers
Related