Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First we start with <em>what</em> a dialog unit is.</p> <p>For that i'll quote one of <a href="https://stackoverflow.com/questions/395195/wpf-how-to-specify-units-in-dialog-units">my own un-answered questions</a>:</p> <blockquote> <h2>What's a dialog unit?</h2> <p>A dialog is a unit of measure based on the user's preferred font size. A dialog unit is defined such that the <em>average character</em> is 4 dialog units wide by 8 dialog units high:</p> <p><img src="https://i.stack.imgur.com/yRvvQ.png" alt="enter image description here"></p> <p>This means that dialog units:</p> <ul> <li>change with selected font</li> <li>changed with selected DPI setting</li> <li>are not square</li> </ul> </blockquote> <p>i'll also quote another of <a href="https://stackoverflow.com/questions/7147716/how-to-specify-units-in-dialog-units-in-wpf">my own un-answered questions</a>:</p> <blockquote> <p>You can check the <a href="https://i.stack.imgur.com/oq4uQ.png" rel="nofollow noreferrer">Windows UX Guidelines</a> to see where these measurements come from. The short version is:</p> <ul> <li>dlu = <em>dialog unit</em></li> <li>dlu is based on the font size (<em>items change with user's font size</em>)</li> <li>a <em>horizontal</em> dlu is different from a <em>vertical</em> dlu (<em>dlu's are not square</em>)</li> </ul> <p>This comes from the definition of a dialog unit: <em>the average character is 8dlus high by 4dlus wide</em>.</p> <p><strong>Georgia 14pt:</strong></p> <p><img src="https://i.stack.imgur.com/oq4uQ.png" alt="enter image description here"></p> <p>If you use a smaller font (i.e. 8pt Tahoma verses 14pt Georgia), the dlus get smaller:</p> <p><strong>Segoe UI 9pt:</strong></p> <p><img src="https://i.stack.imgur.com/LR7DR.png" alt="enter image description here"></p> <p><strong>Note</strong>: You'll notice that <em>resolution</em> (i.e. dpi) has no impact on the discussion.</p> </blockquote> <p>So what you need is the <em>average size</em> of a character. Microsoft has an <a href="http://support.microsoft.com/kb/145994" rel="nofollow noreferrer">official technique</a> for calculating the average character size.</p> <ul> <li><p>average height: </p> <pre><code>GetTextMetrics(dc, {var}textMetrics); averageHeight := textMetrics.tmHeight; </code></pre></li> <li><p>average width:</p> <p>Measure the string <em>ABCDEFGHIJLKMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz</em> using <a href="http://msdn.microsoft.com/en-us/library/dd144938%28v=vs.85%29.aspx" rel="nofollow noreferrer"><code>GetTextExtentPoint32</code></a>, and divide by 52:</p> <pre><code>GetTextExtentPoint32(dc, PChar('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'), 52, Size)); averageWidth := size.cx / 52.0; </code></pre></li> </ul> <p>So now you need the the size of a horizontal and a vertical dialog units. Remember that a horizontal dialog unit is 1/4 the average character width, and a vertical dlu is 1/8 the average character height:</p> <pre><code>procedure GetDlus(dc: HDC; out HorizontalDluSize, VerticalDluSize: Real); var tm: TTextMetric; size: TSize; begin GetTextMetric(dc, tm); VerticalDluSize := tm.tmHeight / 8.0; GetTextExtentPoint32(dc, PChar('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'), 52, size); HorizontalDluSize := size.cx / 52.0; end; </code></pre> <blockquote> <p><strong>Note</strong>: Any code is released into the public domain. No attribution required.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload