title: Creating a find dialog
body: <p>So for this assignment in class I'm making a richtextbox editor in C# winforms, in this assignment I have to include a find function, but I can't seem to get the hang of it
  EDIT: it closes every time I click the search button, but that's not what I want, I want it to close when the user closes the actual dialog via the X in the top right, the search button should just highlight the found string by using the .Find() method</p>
  
  <p>Here's my code up until now:</p>
  
  <pre><code>private void zoekenToolStripMenuItem_Click(object sender, EventArgs e)
  {
      string searchValue = SearchDialog();
      Search(searchValue);
  }
  
  public string SearchDialog()
  {
      Form findDialog = new Form();
      findDialog.Width = 500;
      findDialog.Height = 142;
      findDialog.Text = "Zoeken";
      Label textLabel = new Label() { Left = 10, Top = 20, Text = "Zoek naar:", Width = 100 };
      TextBox inputBox = new TextBox() { Left = 150, Top = 20, Width = 300};
      Button search = new Button() { Text = "Zoek", Left = 350, Width = 100, Top = 70 };
      search.Click += (object sender, EventArgs e) =&gt; { findDialog.Close(); };
      findDialog.Controls.Add(search);
      findDialog.Controls.Add(textLabel);
      findDialog.Controls.Add(inputBox);
      findDialog.ShowDialog();
      return (string)inputBox.Text;
  }
  
  void Search(string searchValue)
  {
      rtxtInhoud.Find(searchValue);
  }
  </code></pre>
  
  <p>The part: 
      <code>search.Click += (object sender, EventArgs e) =&gt; { findDialog.Close(); };</code>
  is what I'm really stuck on
  Thanks in advance</p>
  
  <p>EDIT: here's something that I tried to do, which didn't work</p>
  
  <pre><code>public string SearchDialog()
  {
     Form findDialog = new Form();
     findDialog.Width = 500;
     findDialog.Height = 142;
     findDialog.Text = "Zoeken";
     Label textLabel = new Label() { Left = 10, Top = 20, Text = "Zoek naar:", Width = 100 };
     TextBox inputBox = new TextBox() { Left = 150, Top = 20, Width = 300};
     Button search = new Button() { Text = "Zoek", Left = 350, Width = 100, Top = 70 };
     Button findNext = new Button() { Text = "Volgende", Left 250, Width = 100, Top = 70};
     search.Click += (object sender, EventArgs e) =&gt; { rtxtInhoud.Find(inputBox.Text); };
     findDialog.Controls.Add(search);
     findDialog.Controls.Add(textLabel);
     findDialog.Controls.Add(inputBox);
     findDialog.ShowDialog();
     return (string)inputBox.Text;
  }
  </code></pre>
  
  <p>This waits for the Dialog to be closed before highlighting the found string. Which is NOT what I want, I want it to keep the Dialog open, but still highlight the text</p>