I’d like to use Segoe UI 9 pt on Vista, and Tahoma 8 pt on Windows XP/etc. (Actually, I’d settle for Segoe UI on both, but my users probably don’t have it installed.) But, these being quite different, they really screw up the layout of my forms. So… is there a good way to deal with this?
An example: I have a Label, with some blank space in the middle, into which I place a NumericUpDown control. If I use Segoe UI, the NumericUpDown is about 5 pixels or so to the left of the blank space, compared to when I use Tahoma. This is a pain; I’m not sure what to do here.
So most specifically, my question would be: how can I place controls in the middle of a blank space in my Labels (or CheckBoxes, etc.)? Most generally: is there a good way to handle varying fonts in Windows Forms?
Edit: I don’t think people understood the question. I know how to vary my fonts based on OS. I just don’t know how to deal with the layout problems that arise from doing so.
Reply to ajryan, quick_dry: OK, you guys understand the question. I guess MeasureString might work, although I’d be interested in further exploration of better ways to solve this problem.
The problem with splitting the control is most apparent with, say, a CheckBox. There, if the user clicks on the ‘second half’ of the CheckBox (which would be a separate Label control, I guess), the CheckBox doesn’t change state.
It’s strange to need to layout one control within another. You might be solving an upstream problem wrong. Are you able to split the label into two labels with the updown between and maybe rely on a Windows Forms TableLayout panel?
If it’s essential to try to position based on font sizes, you could use Graphics.MeasureString(‘String before updown’, myLabel.Font)
If what you’re after is font-dependent control positioning, you should probably retitle the question.
[edit] You can handle the click event of the ‘second half’ part of the label and change the checkbox state on that event. The whole thing seems like a hack though. What is the problem being solved by this weird control layout? Why do you need an up-down in the middle of a label?