在winform里,有两个textbox1,textbox2,textbox2中有很多内容,在textbox1中输入关键字,要在textbox2中,如果有则找到相关的内容,没有就返回。谢谢了啊

解决方案 »

  1.   

    if text1.text.indexof("a")>0 ....
      

  2.   

    string keyWord = text1.Text.Trim();
    string context = text2.Text;
    if(context.IndexOf(keyWord) > 0)
    {
       //找到...
    }
      

  3.   

    非常感谢上面的啊,
    如果有好几个都匹配的怎么办?
    而且最好是能找到一个 标记一个,这样就象我们的Ctrl+F这样的效果?
    该怎么搞?
      

  4.   

    private int position = 0;private void Button1_Click(object sender, System.EventArgs e)
    {
    if ((position = text2.Text.IndexOf(text1.Text.Trim(), position)) < 0) 
    {
    position = 0;
    MessageBox.Show ("搜索已到达文档末尾");
    }
    else
    {
    text2.Select(position, text1.Text.Trim().Length);
    position += text1.Text.Trim().Length;
    }
    }