Wednesday, May 13, 2015

DPI Frustration

Yesterday I tested my Windows Forms application at a high DPI setting and discovered that it got completely messed up at that scale. I did some Googling, and learned that I had to remove the form-wide font setting because it caused a reset of all child controls' sizes. Once I set my preferred font face (Segoe UI) on all the individual controls, the form looked a lot better.

However, there was a misalignment involving a Label and LinkLabel, anchored to the bottom-right of the form. The Label was on top, with AutoSize set to False because its text had to be changed at runtime. (Right-anchored auto-sized Label controls get messed up when their text is changed.) Under it was the LinkLabel, which was horizontally aligned with another LinkLabel on the other side, at the bottom-left. Both LinkLabels are auto-sized. The problem was that the LinkLabel - only the one on the right side - got pushed to the left at high DPI.

I tried making the LinkLabel non-auto-sized, but that caused its underline to be clipped off at high DPI. Making the control extra-tall would create undesirable extra spacing between it and the Label immediately above. (They go together.)

I then tried a TableLayoutPanel. I gave the top row - the one containing the fixed-size Label - a fixed height, and let the bottom row with the LinkLabel auto-size. That fixed the horizontal alignment, but the TableLayoutPanel shifted up at high DPI, removing the horizontal alignment between the two LinkLabel controls. No amount of Anchor adjustment helped.

My current resolution is to accept the non-alignment of the Label and LinkLabel and go with the simple initial arrangement. It doesn't look terrible, and it only happens at high DPI. I might have to consider WPF if I run into worse issues.

No comments:

Post a Comment