SizeGripStyle in DPI-aware app

221 Views Asked by At

I have a problem with the form's property SizeGripStyle in different DPI. My forms have property AutoScaleMode set to Font and enable scaling using API (because of ClickOnce app). The grip somehow goes below a form. On the internet I didn't find any mention. Any idea how to fix it, if possible?

There you have pics of grip's behavior on different DPI

The program is in C# 4.0 and WF.

1

There are 1 best solutions below

0
On BEST ANSWER

This is a bug in Windows itself. Winforms asks the visual style renderer to draw the grip. It flubs the job badly, instead of making it bigger it makes it smaller. It actually should do neither, you specify the rectangle it should fill with the grip. Heck of a bug, not entirely uncommon for the visual style renderer unfortunately.

Very little you can do about it, hopefully they'll fix the bug some day. But one thing, you'll have to draw the grip yourself. Set the form's SizeGripStyle property back to Auto and override OnPaint() to draw it:

protected override void OnPaint(PaintEventArgs e) {
    base.OnPaint(e);
    var gripSize = (int)(16 * e.Graphics.DpiX / 96f);
    var rc = new Rectangle(this.ClientSize.Width - gripSize, 
                           this.ClientSize.Height - gripSize, gripSize, gripSize);
    ControlPaint.DrawSizeGrip(e.Graphics, this.BackColor, rc);
}

Not quite as pretty as the "dimple" style you get from the visual styles render, you could also consider drawing a bitmap but you'll need several versions of it to match the DPI.