我有2種形式代碼問題。在RTB搜索文本C#
一個包括一個RichTextBox另一種是用在這個RTB
我的代碼是否顯示錯誤,我不知道如何解決它來搜索文本。
這是顯示錯誤
RichTextBox box = ((Form1)base.Owner).rtxtEditor;
它稱該行「對象引用不設置到對象的實例。」
這是我的整個代碼。
private void frmFind_Shown(object sender, EventArgs e)
{
this.txtSearch.Focus();
}
private void cmdFind_Click(object sender, EventArgs e)
{
RichTextBox box = ((Form1)base.Owner).rtxtEditor;
int start = box.Find(this.txtSearch.Text, 0);
if (start == -1)
{
this.lblMatch.Text = "No match found";
this.cmdFindNext.Enabled = false;
}
else
{
this.lblMatch.Text = "";
box.Select(start, this.txtSearch.Text.Length);
this.cmdFindNext.Enabled = true;
box.ScrollToCaret();
((Form1)base.Owner).Focus();
}
}
private void cmdFindNext_Click(object sender, EventArgs e)
{
RichTextBox box = ((Form1)base.Owner).rtxtEditor;
int start = box.Find(this.txtSearch.Text, ((Form1 base.Owner).rtxtEditor.SelectionStart + 1, 0);
if (start == -1)
{
this.lblMatch.Text = "No more matches";
this.cmdFindNext.Enabled = false;
}
else
{
box.Select(start, this.txtSearch.Text.Length);
box.ScrollToCaret();
((Form1)base.Owner).Focus();
}
請幫忙!我我的截止日期是2morrow
你是同一個人http://stackoverflow.com/users/278779/pops還是你在他的課堂上? – SLaks 2010-02-28 18:28:25