<p>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?</p>

<p>An example: I have a <code>Label</code>, with some blank space in the middle, into which I place a <code>NumericUpDown</code> control. If I use Segoe UI, the <code>NumericUpDown</code> 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.</p>

<p>So most specifically, my question would be: how can I place controls in the middle of a blank space in my <code>Label</code>s (or <code>CheckBox</code>es, etc.)? Most generally: is there a good way to handle varying fonts in Windows Forms?</p>

<p><strong><em>Edit</em></strong>: I don't think people understood the question. I know how to <em>vary my fonts</em> based on OS. I just don't know how to <em>deal with the layout problems</em> that arise from doing so.</p>

<p><strong><em>Reply to ajryan, quick_dry</em></strong>: 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.</p>

<p>The problem with splitting the control is most apparent with, say, a <code>CheckBox</code>. There, if the user clicks on the "second half" of the CheckBox (which would be a separate <code>Label</code> control, I guess), the <code>CheckBox</code> doesn't change state.</p>

[{'answer_id': 37313, 'author': 'Jon Limjap', 'author_id': 372, 'author_profile': 'https://Stackoverflow.com/users/372', 'pm_score': 1, 'selected': False, 'text': '<p>First of all, you can find out which version of Windows you are using with the <a href="http://msdn.microsoft.com/en-us/library/system.operatingsystem.platform.aspx" rel="nofollow noreferrer">OperatingSystem.Platform</a> property in the System library.</p>\n\n<p>Second, it is possible that you may put your font settings in Resource files, and determine which resource file to use depending on certain conditions (e.g., your operating system version).</p>\n\n<p>Personally though, I think it would be nice to let your user determine the fonts that <em>they</em> prefer as opposed to the font that you want for them to use.</p>\n\n<p>Finally, you might want to take a look at <a href="http://windowsclient.net/" rel="nofollow noreferrer">WPF</a> as this is one of the problem spaces that it was designed to solve.</p>\n'}, {'answer_id': 37365, 'author': 'quick_dry', 'author_id': 3716, 'author_profile': 'https://Stackoverflow.com/users/3716', 'pm_score': 1, 'selected': False, 'text': "<p>is the problem working out the placement of controls? i.e. you know font X and Y work on OS A and B, and give the layout you want with the text you're using on those systems?</p>\n\n<p>MeasureString method might help in working out your layout in a way that you weren't tied to specific fonts.</p>\n\n<p>float textWidth = graphics.MeasureString(someString, someFont).Width;</p>\n\n<p>(would a change in text alignment work? I might be misunderstanding the problem too)</p>\n"}, {'answer_id': 37371, 'author': 'Aidan Ryan', 'author_id': 1042, 'author_profile': 'https://Stackoverflow.com/users/1042', 'pm_score': 2, 'selected': True, 'text': '<p>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? </p>\n\n<p>If it\'s essential to try to position based on font sizes, you could use <a href="http://msdn.microsoft.com/en-us/library/6xe5hazb.aspx" rel="nofollow noreferrer">Graphics.MeasureString</a>("String before updown", myLabel.Font)</p>\n\n<p>If what you\'re after is font-dependent control positioning, you should probably retitle the question.</p>\n\n<p><hr>\n[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?</p>\n'}, {'answer_id': 37864, 'author': 'rpetrich', 'author_id': 4007, 'author_profile': 'https://Stackoverflow.com/users/4007', 'pm_score': 2, 'selected': False, 'text': "<p>I second the usage of TableLayoutPanel for single-line inline controls.</p>\n\n<p>I usually set each column and the first row to AutoSize and set each child control's Dock property to Fill in the designer. That gets the horizontal layout to display properly.\nTo make the the text line up between labels/textboxes, set the TextAlign property to MiddleLeft.</p>\n\n<p>If your text flows onto to the next line there's no easy solution. Using Graphics.MeasureString/TextRenderer.MeasureText and some fancy wrapping logic is your best bet :(</p>\n"}]
['https://Stackoverflow.com/questions/37306', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3191/']