Mimic Notepad menuEditFind

  • Thread starter Thread starter James Morton
  • Start date Start date
J

James Morton

I am trying to mimic the behavior of notepad where the find form stays in
front and active yet the text form actively highlights the search string.
Right now I have to close the find form in order to see the highlighted
text.

What do I need to do? Here is what I have now (note I am using the text
forms in an MDI.

in the main form

private void menuEditFind_Click(object sender, System.EventArgs e)

{

frmFind f = new frmFind(this);

f.Show();

}



public void FindNext(string str, frmFind f)

{

try

{

Form activeChild = this.ActiveMdiChild;

TextBox activeTextBox = (TextBox)activeChild.ActiveControl;

activeTextBox.Select(activeTextBox.Text.IndexOf(str), str.Length);

}

catch(Exception ex)

{

MessageBox.Show(ex.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error
);

}

}





In form find

private System.Windows.Forms.Form frmParent;



public frmFind(frmMain f)

{

frmParent = f;

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

}



private void btFindNext_Click(object sender, System.EventArgs e)

{

frmMain f = (frmMain)frmParent;

f.FindNext(tbSearchString.Text, this);

}





Thanks!!!!!



James M
 
Back
Top