Wednesday, March 23, 2011

Changing default font in Windows messes up my Win Forms buttons.

We have a collection of C# (.NET 2.0) applications that have custom dialog windows. When the user changes the default font size and resolution etc in Windows the edges of the form lose controls (they get pushed off the visible portion of the form) typically dropping off buttons from the bottom. This is problematic for us and will cause issues across other applications using the standard look-and-feel framework we are creating around these applications.

How would you make your entire application independent from windows font changes? How would you integrate this into multiple solutions?

Or better still how can one adapt the entire application to be able to adjust itself with the Windows appearance changes?

From stackoverflow
  • You could handle the SystemEvents.UserPreferenceChanged event in the Microsoft.Win32 namespace. The UserPreferenceChangedEventArgs parameter will have a Category of UserPreferenceCategory.Window when the system font changes. I think you'll then have to trigger a manual window layout and redraw in response to this event.

    bdwakefield : I will look into this, but I don't think the problem results specifically from it being change during program execution. We think it comes more from just being changed from the default.
  • WinForms have the AutoScaleMode property, which can be set to either Font, DPI, Inherit, or None. The default is "Font" which, in my experience, doesn't always scale things right. You might try one of the other options (maybe "None" if you don't want your form to scale at all?)

    As for making the entire application able to adjust itself, look into the "Inherit" option (you still need to set something other than "Inherit" on the parent or startup form of your application, though).

    bdwakefield : Ideally, we don't want the IU to change at all. The of the biggest driving reasons behind creating this framework was to give us a way to make all of the applications look and feel the same. I think this is what I am looking for. I will try this out. Thanks.

0 comments:

Post a Comment