title: C# Resize textbox to fit content
body: <p>I'm writing a program where the user should be able to write text in a <code>TextBox</code>. I'd like the <code>TextBox</code> to resize itself, so it fits to the content.
  I've tried the following:</p>
  <pre><code>private void textBoxTitle_TextChanged(object sender, TextChangedEventArgs e)
  {
      System.Drawing.Font myFont = new System.Drawing.Font(&quot;Verdana&quot;, 8);
      System.Drawing.SizeF mySize = e.Graphics.MeasureString(&quot;This is a test&quot;, myFont);
      this.textBoxTitle.Width = (int)Math.Round(mySize.Width, 0);
  }
  </code></pre>
  <p>I get an error saying that <code>Graphics</code> doesn't work for <code>TextChangedEventArgs</code>. Is there another way I can resize the <code>TextBox</code>?</p>