事件的嵌套触发

本文关键字:嵌套 事件 | 更新日期: 2023-09-27 18:25:28

我的表单中有一个富文本框、列表框、复选框和一个按钮。富文本框已加载文本文件。我正在富文本框中搜索选中列表框的字符串,并将找到的字符串的索引添加到列表框中。在鼠标双击错误列表事件时,我将光标设置为字符串的特定索引位置。

现在我计划在表单中再添加两个按钮Next和previous。它将选择列表框的下一个和上一个项目,并且光标应指向该位置。如何做到这一点。也就是说,单击下一个按钮时,所选项目应该是当前项目的下一个,为此,我应该调用鼠标双击事件。

 private void lstErrorList_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            //rtbFileDisplay.Cursor = Cursors.WaitCursor;
            MessageBox.Show(lstErrorList.SelectedIndex.ToString());
            int val;
            string val1 = lstErrorList.Text;
            val1 = val1.Remove(0, val1.Length - 8);
            string replacement = Regex.Replace(val1, @"'t|'n|'r|[a-zA-Z]","");
            val = Convert.ToInt32(replacement);
            rtbFileDisplay.Select(val, 0);
            rtbFileDisplay.Focus();
        }
 private void btnNextError_Click(object sender, EventArgs e)
        {
            if (lstErrorList.Items.Count != 0)
            {
                if (lstErrorList.SelectedIndex != lstErrorList.TopIndex)
                    lstErrorList.SelectedIndex++;
                //lstErrorList.SelectedItem = int.Parse(lstErrorList.SelectedItem + 1);
            }
    }

事件的嵌套触发

不一定被认为是好的做法,但如果您只是忽略了sender和eventargs,那么您可以用"null"来调用任何事件。