title: C# Graphics.DrawString RectangleF Auto-Height: How to find that height?
body: <p>I am writing text over an image using Graphics DrawString method, binding my text with a RectangleF. Here is my code: </p>
  
  <pre><code>//Write header2
  RectangleF header2Rect = new RectangleF();
  header2Rect.Width = 600;
  header2Rect.Location = new Point(30, 105);
  graphicImage.DrawString(header2, new Font("Gotham Medium", 28, FontStyle.Bold),brush, header2Rect);
  //Write Description
  RectangleF descrRect = new RectangleF();
  descrRect.Width = 600;
  int measurement = ((int)graphicImage.MeasureString(header2, new Font("Gotham Medium", 28, FontStyle.Bold)).Height);
  var yindex = int.Parse(105 + header2Rect.Height.ToString());
  descrRect.Location = new Point(30, 105+measurement);
  graphicImage.DrawString(description.ToLower(), new Font("Gotham", 24, FontStyle.Italic), SystemBrushes.WindowText, descrRect);
  </code></pre>
  
  <p>This works for some cases (ie. when <code>header2</code> is only 1 line long), but my <code>measurement</code> variable only measures the height of the Font, not the whole <code>DrawString</code> rectangle. I do not want to set a static <code>header2Rect</code> height because the heights change depending on that text. </p>
  
  <p>yindex does not work because <code>header2Rect.Height = 0</code>. Is there a way to see how many lines my <code>header2</code> is? </p>
  
  <p>Do I just need to do <code>MeasureString</code> width and divide that by my boundary rectangle width, then multiply by the <code>MeasureString</code> height? I'm assuming there is a better way.</p>
  
  <p>Thanks</p>
  
  <p>[EDIT] It looks like the height is actually 0 but the text just overflows outside, but the width still constricts the text-wrapping. I just did some math calculations to find the height, but I wish there was a better way.</p>