title: Center text output from Graphics.DrawString()
body: <p>I'm using the .NETCF (Windows Mobile) <code>Graphics</code> class and the <code>DrawString()</code> method to render a single character to the screen.</p>
  
  <p>The problem is that I can't seem to get it centred properly. No matter what I set for the Y coordinate of the location of the string render, it always comes out lower than that and the larger the text size the greater the Y offset.</p>
  
  <p>For example, at text size 12, the offset is about 4, but at 32 the offset is about 10.</p>
  
  <p>I want the character to vertically take up most of the rectangle it's being drawn in and be centred horizontally. Here's my basic code. <code>this</code> is referencing the user control it's being drawn in.</p>
  
  <pre><code>Graphics g = this.CreateGraphics();
  
  float padx = ((float)this.Size.Width) * (0.05F);
  float pady = ((float)this.Size.Height) * (0.05F);
  
  float width = ((float)this.Size.Width) - 2 * padx;
  float height = ((float)this.Size.Height) - 2 * pady;
  
  float emSize = height;
  
  g.DrawString(letter, new Font(FontFamily.GenericSansSerif, emSize, FontStyle.Regular),
              new SolidBrush(Color.Black), padx, pady);
  </code></pre>
  
  <p>Yes, I know there is the label control that I could use instead and set the centring with that, but I actually do need to do this manually with the <code>Graphics</code> class.</p>