title: Custom control dynamic size C#
body: <p>I have a UserControl with one textbox on it. I wan't to change the control size depending on the font size, so that it doesn't cut off the bottom of the text, but the changes I'm making to the control size are taking no effect at all.</p>
  
  <pre><code>public override Font Font
  {
      get
      {
          return base.Font;
      }
      set
      {
          textBox1.Font = base.Font = value;
          if (Font.Height != this.Height)
              this.Height = Font.Height;
      }
  }
  
  protected override void OnResize(EventArgs e)
  {
      textBox1.Size = new Size(this.Width - (_textboxMargin * 2 + _borderWidth * 2), this.Height - (_textboxMargin * 2 + _borderWidth * 2));
      textBox1.Location = new Point(_textboxMargin, _textboxMargin);
  
      base.OnResize(e);
  }
  </code></pre>
  
  <p>When the OnResize event is fired after the property has been set, this.Height remains the original value.</p>
  
  <p>--EDIT--</p>
  
  <p>As it turns out the problem was that I set the Font before the control size, so it get overwritten. But this is happening in the designer of the page where I'm using this control. How can I prevent this from happening in the future?</p>