How to handle the size of controls in WinForm application for different font size/localized text?

StackOverflow https://stackoverflow.com/questions/18979052

  •  29-06-2022
  •  | 
  •  

Question

I am facing one same problem for trying to support any of the followings in a WinForm application:

  1. An option that allow users to change font and font size in all memos/labels/buttons/edits/combos/grids/..etc controls.
  2. Localization where the length/size of the text changes in different languages (and would need a larger font size)
  3. "Windows Color and Appearance" settings which let you change font and font size

The problem is that the size/location/layout of the controls would be all messed up due to the changing size. Either a control can't show all its content, or an autosized control would overlap other controls, or gets clipped by the bound of a parent control, or have problems with wordwrap, or...etc.

The controls are usually some memos/labels/buttons/edits/combos/grids/..etc simply placed on a panel/groupbox/tab/..etc, or combinations of such controls nested in other container controls. I wonder if there are some easy standard less-painful way to handle this problem. (Also, wonder if there are some easy or standard way to make controls pick up the font setting automatically instead of assigning the fonts manually.)

Thanks in advance.

Was it helpful?

Solution

I would suggest placing controls in containers designed for the purpose...such as a TableLayoutPanel. Perhaps even nested panels, if your layout is complex. With that, you can allow most things to AutoSize, and control positions based on percentages of overall width/height.

OTHER TIPS

As far as I could understand, you want to change the font size for all your controls, and fear that those changes would ruin your layout.

First you need to figure out how are you going to handle larger/longer text. You can wrap strings or trim the tails, or you can make your layout larger, while keeping the proportions of your controls the same. Other than that, I don't think there's any easy solution for handling arbitrary changes to font-size/language.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top