We have an existing windows .net application in which it uses all custom controls.
Things were fine these many days as we were just supporting the default 96 dpi resolution.
Now that we need our application to be dpi-aware. Things are going haywire when we go to next
higher resolution 120 or 144 etc.
Most common issues
Bitmap scaling issues and
Text cut-off
After going through these MSDN docs and existing SO questions I tried to
incorporate such a fix in vain inside my application (since all the controls used are
customized and are not dpi-aware).
Things I tried after modifying my application.manifest to enable the dpi-awareness flag and setting the AutoScaleMode to AutoScaleMode.Dpi on the main form and other forms use the AutoScaleMode as Inherit
- Changed the control Font inside the OnLoad event
Graphics g = this.CreateGraphics(); int dpi = int.Parse(g.DpiX.ToString());
switch (dpi)
{
case 125:
this.Font = new Font(this.Font.FontFamily, this.Font.Size * 125.0f / (float)(g.DpiX));
Debug.WriteLine("<<---- Selected DPI Resolution :" + " 125 DPI ---->");
break;
... so on
- Tried overriding the ScaleControl method to make use of different scaling factor based on DPI
But all these never seem to work in my case.
Does anyone know / suggest me a better approach to tackle this issue.
Thanks
VATSAG