views:

82

answers:

2

I want to run my application on 96dpi, no matter what the dpi size from Windows is set to. It is possible ?

' Edit ' I found that using the Scale() method and resizing the font will almost do the trick.

public class MyForm : Form
{
    private static bool ScaleDetected = false;
    const float DPI = 80F;

    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);

        if (!ScaleDetected)
        {
            Graphics g = e.Graphics;
            float factorX = DPI / g.DpiX;
            float factorY = DPI / g.DpiY;

            SizeF newSize = new SizeF(factorX, factorY);

            AutoScaleDimensions = newSize;
            AutoScaleMode = AutoScaleMode.Dpi;

            Scale(newSize);
            Font = new Font(Font.FontFamily, Font.Size * factorX);

            ScaleDetected = true;
        }
    }
}

alt text

However when using this 'trick' in a MDI application using Janus Controls, the main form is resized, but for some other forms, the scaling + changed font are not applied.

A: 

If I understand correctly you want to disable the automatic DPI scaling. If so, I think that you just need to call SetProcessDPIAware to tell Windows that you'll handle it yourself.

See this link for how to call it from C#/VB.Net:
http://www.pinvoke.net/default.aspx/user32/setprocessdpiaware.html

ho1
This does only work for Vista, and I need it for Windows XP.
Stef