C# richTextBox做的记事本程序,替换功能问题
//替换功能代码段:publicvoidReplace(stringstrOld,stringstrReplace){if(searchPosition>richText...
//替换功能代码段:
public void Replace(string strOld, string strReplace)
{
if (searchPosition > richTextBox1.Text.Length)
{
return;
}
searchPosition = richTextBox1.Find(strOld, searchPosition, RichTextBoxFinds.MatchCase);
if (searchPosition == -1)
{
searchPosition = 0;
}
else
{
richTextBox1.Focus();
richTextBox1.SelectionStart = searchPosition;
richTextBox1.SelectionLength = strOld.Length;
searchPosition += strOld.Length;
richTextBox1.SelectedText = strReplace;
}
}
//替换按钮被单击发生事件:
private void buttonReplace_Click(object sender, EventArgs e)
{
form1.Replace(richTextBox1.Text, richTextBox2.Text);//调用替换功能
}
//全部替换按钮事件
private void buttonReplaceAll_Click(object sender, EventArgs e)
{
while (form1.searchPosition< fileLength )
{
buttonReplace_Click(sender, e);
}
}
}
用C#做了个记事本的程序,发现替换功能只有替换有效,点击全部替换无效,求教各位前辈,问题出在哪里呢? 展开
public void Replace(string strOld, string strReplace)
{
if (searchPosition > richTextBox1.Text.Length)
{
return;
}
searchPosition = richTextBox1.Find(strOld, searchPosition, RichTextBoxFinds.MatchCase);
if (searchPosition == -1)
{
searchPosition = 0;
}
else
{
richTextBox1.Focus();
richTextBox1.SelectionStart = searchPosition;
richTextBox1.SelectionLength = strOld.Length;
searchPosition += strOld.Length;
richTextBox1.SelectedText = strReplace;
}
}
//替换按钮被单击发生事件:
private void buttonReplace_Click(object sender, EventArgs e)
{
form1.Replace(richTextBox1.Text, richTextBox2.Text);//调用替换功能
}
//全部替换按钮事件
private void buttonReplaceAll_Click(object sender, EventArgs e)
{
while (form1.searchPosition< fileLength )
{
buttonReplace_Click(sender, e);
}
}
}
用C#做了个记事本的程序,发现替换功能只有替换有效,点击全部替换无效,求教各位前辈,问题出在哪里呢? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询