title: Making a WinForms TextBox behave like your browser's address bar
body: <p>When a C# WinForms textbox receives focus, I want it to behave like your browser's address bar.</p>
  
  <p>To see what I mean, click in your web browser's address bar. You'll notice the following behavior: </p>
  
  <ol>
  <li>Clicking in the textbox should select all the text if the textbox wasn't previously focused.</li>
  <li>Mouse down and drag in the textbox should select only the text I've highlighted with the mouse.</li>
  <li>If the textbox is already focused, clicking does not select all text.</li>
  <li>Focusing the textbox programmatically or via keyboard tabbing should select all text.</li>
  </ol>
  
  <p>I want to do exactly this in WinForms.</p>
  
  <p><strong>FASTEST GUN ALERT: please read the following before answering!</strong> Thanks guys. :-)</p>
  
  <blockquote>
    <p><strong>Calling .SelectAll() during
    the .Enter or .GotFocus events won't
    work</strong> because if the user clicked the
    textbox, the caret will be placed
    where he clicked, thus deselecting all
    text.</p>
    
    <p><strong>Calling .SelectAll() during the .Click event won't work</strong> because the user won't be able to select any text with the mouse; the .SelectAll() call will keep overwriting the user's text selection.</p>
    
    <p><strong>Calling BeginInvoke((Action)textbox.SelectAll) on focus/enter event enter doesn't work</strong> because it breaks rule #2 above, it will keep overriding the user's selection on focus.</p>
  </blockquote>