你每次查找事件被觸發的時候讓richtextbox強制獲得焦點不行嘛?

解决方案 »

  1.   

    明灭由心,怎样强制获得richtextBox.Focus ()吗?这样不行,我心太乱,能否说的具体点?
      

  2.   

    我用的是两个窗体
    主窗体
    private void butCz_Click(object sender, System.EventArgs e)
    {
    findpro();

    } private void findpro()
    {
    Cz dlgCz= new Cz();
    dlgCz.ShowDialog();
    dlgCz.Focus ();
    dlgCz.findString =findStr;
    // Determine the state of the DialogResult property for the form.
    if (dlgCz.DialogResult == DialogResult.OK) 
    {
    this.richTextBox1 .Focus ();
    findStr=dlgCz.findString.Trim () ;
    int str=this.richTextBox1 .SelectionStart;
    //MessageBox.Show (findStr);
    if(this.richTextBox1 .SelectionLength >0)//如果已经找到第一个,下一个从后面的字符开始
    str++;
    int result=this.richTextBox1 .Text .IndexOf(findStr,str);
    if(result>-1)
    {
    this.richTextBox1 .SelectionStart =result;
    this.richTextBox1 .SelectionLength =findStr.Length ;
    }
    else
    {
    MessageBox.Show (this,"找不到\""+findStr+"\"","编辑器",MessageBoxButtons.OK);
    }
    findpro();

    }
    else
    {
    dlgCz.Close ();
    } }查找窗体:
    public Cz()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent();
    ff=new Form1();
    this.textBox1 .Text =ff.findStr;
    if (this.textBox1 .Text !="")


    this.butQd.Enabled =true;

    else
    this.butQd.Enabled =false; //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    }有一个findString属性
    public string findString
    {
    get
    {
    s=this.textBox1 .Text ;
    return s;
    }
    set
    {
    value=value.Trim ();
    s=value;

    }


    }