Search code examples
c#screenwindows-8.1tablet

SP3 can't seem to get screen size in C#?


I've been working on a simple application to retrieve screenshots on Windows. The code I have works great on everything but a Surface Pro. I can't seem to retrieve the screen dimensions dynamically and it seems stuck on giving me a 1420x968 working area no matter what.

Rectangle bounds = this.Bounds; //SP3 dimensions new Rectangle(0, 0, 2160, 1440);

using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
    using (Graphics g = Graphics.FromImage(bitmap))
    {
        g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
    }
    bitmap.Save(dirToUse + accessionNumber + ".jpg", ImageFormat.Jpeg);
}

Solution

  • Try telling Windows your application is DPI aware in the manifest file.

    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
       <asmv3:application>
            <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
                 <dpiAware>true</dpiAware>
            </asmv3:windowsSettings>
       </asmv3:application>
    </assembly>
    

    More here.