title: How to align right edges of a control and ToolTip Message in C#
body: <p>I want to display a <code>ToolTip</code> message below a <code>TextBox</code>, but also want them to be right aligned. </p>
  
  <p>I was able to position the ToolTip message at the right edge of the textbox, so I tried to move the message left by message length.</p>
  
  <p>So I tried to get the string length by using <em>TextRenderer.MeasureText()</em>, but the position is a little bit off as shown below.</p>
  
  <p><a href="https://i.stack.imgur.com/6umIv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6umIv.png" alt="current result"></a></p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)
  {
     ToolTip myToolTip = new ToolTip();
  
     string test = "This is a test string.";
     int textWidth = TextRenderer.MeasureText(test, SystemFonts.DefaultFont, textBox1.Size, TextFormatFlags.LeftAndRightPadding).Width;
     int toolTipTextPosition_X = textBox1.Size.Width - textWidth;
  
     myToolTip.Show(test, textBox1, toolTipTextPosition_X, textBox1.Size.Height);
  }
  </code></pre>
  
  <p>I tried with different flags in the <em>MeasureText()</em> function but it didn't help, and since ToolTip message has a padding, I went for <em>TextFormatFlags.LeftAndRightPadding</em>.</p>
  
  <p>To be clear, this is what I would like to achieve:</p>
  
  <p><a href="https://i.stack.imgur.com/58vzL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/58vzL.png" alt="desired output"></a></p>