Font Dependent Positioning

I would like to use Segoe UI 9 pt for Vista and Tahoma 8 pt for Windows XP, etc. (Actually, I agree with Segoe UI on both, but my users probably don’t install it.) But, it’s completely different, they really messed up the layout of my forms. So ... is there a good way to handle this?

Example: I have a Label , with some space in the middle in which I put the NumericUpDown control. If I use the Segoe user interface, NumericUpDown is about 5 pixels or so to the left of the space, compared to when I use Tahoma. It is a pain; I'm not sure what to do here.

So, in particular, my question is: how can I place controls in the middle of a space in Label (or CheckBox es, etc.)? In general: is there a good way to handle different fonts in Windows Forms?

Change I do not think that people understood this question. I know how to change OS based fonts. I just don’t know how to deal with layout problems that arise because of this.

Reply to ajryan, quick_dry : Well, you guys understand the question. I think MeasureString might work, although I would be interested to continue exploring the best ways to solve this problem.

The problem with splitting a control is most obvious, say, in CheckBox . There, if the user clicks on the “second half” of the CheckBox (which, I believe, will be a separate Label control), the CheckBox does not change state.

+2
user-interface fonts layout winforms
Sep 01 '08 at 0:32
source share
4 answers

It is strange that you need to place one control in another. Perhaps you are not solving the upstream problem correctly. Can you split a label into two labels with an update between them and possibly rely on the Windows Forms TableLayout panel?

If you need to try positioning by font size, you can use Graphics.MeasureString ("String before updown", myLabel. Font)

If what you are behind is font-dependent positioning control, you should probably redirect the question.




[edit] You can handle the click event of the "second half" part of the label and change the state of the flag on this event. However, all this seems like a hack. What is the problem solved by this weird control layout? Why do you need up and down in the middle of a shortcut?
+1
Sep 01 '08 at 2:08
source share

Secondly, the use of TableLayoutPanel for single-line inline controls.

I usually set each column and first row in AutoSize and set each child Dock property to fill in the constructor. This allows you to display the horizontal layout. To keep the text line between labels / text fields, set the TextAlign property to MiddleLeft.

If your text moves to the next line, there is no easy solution. Using Graphics.MeasureString / TextRenderer.MeasureText and some flow logic is your best bet :(

+3
Sep 01 '08 at 12:25
source share

First of all, you can find out which version of Windows you are using with OperatingSystem.Platform in the system library.

Secondly, it is possible that you can put the font settings in resource files and determine which resource file to use depending on certain conditions (for example, the version of your operating system).

Personally, I think it would be nice to let your user define the fonts they prefer, as opposed to the font you want to use.

Finally, you can take a look at WPF , as this is one of the problem spaces that it is intended to solve.

+1
Sep 01 '08 at 0:45
source share

- a problem with the placement of controls? those. Do you know that the fonts X and Y work with OS A and B and give the desired layout with the text that you use in these systems?

The MeasureString method can help design your layout so that you are not tied to specific fonts.

float textWidth = graphics.MeasureString (someString, someFont) .Width;

(will there be a change in the alignment of the text? Perhaps I also misunderstand the problem)

+1
Sep 01 '08 at 2:02
source share



All Articles