日期:2014-05-17  浏览次数:20738 次

richtextbox的find方法在有子窗体的情况下如何显示出来。
richtextbox在主窗体上,主窗体按查找功能后,弹出查找窗口find,然后通过委托,实现不同窗体间传值,可是查找到后,如果子窗体还在,没关掉,主窗体是不会突出显示查找到的字符串的,只有关闭了子窗口才显示,请问这个问题怎么解决,下面是我的代码

主窗体代码
C# code

find fd = new find();//子窗体名字,find
int i =0;
private void 查找ToolStripMenuItem_Click(object sender, EventArgs e)
{
           
    fd.MyPing+=new find.PING(fd_MyPing);//关联委托
    fd.Show(this);
}
void fd_MyPing(string str) //委托的处理事件
{

    int an = richTextBox1.Find(str, i, RichTextBoxFinds.MatchCase);
    if (an >0)
    {
       this.richTextBox1.Select(an, str.Length);
       i = an + str.Length;
    } 
    else
    {
       MessageBox.Show("没有查找到相符的字符串");
    }          
}





子窗体代码
C# code

public delegate void PING(string str);//定义委托
public event PING MyPing;

private void button1_Click(object sender, EventArgs e)
{
  this.MyPing(this.textBox1.Text);
}