仿微软,简单功能齐全的notepad记事本程序和源码,提供给初学者交流和学习。
对search方法略作修改,查不到字符时返回起始位置;
public void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.Length > 0)
{
str = textBox1.Text;
fm.searchStr = textBox1.Text;
fm.matchCase = checkBox1.Checked;
fm.upCheck = radioButton1.Checked;
}
else
{
str = fm.searchStr;
checkBox1.Checked = fm.matchCase;
radioButton1.Checked = fm.upCheck;
}
if (str == null)
{
MessageBox.Show("找不到" + str, "记事本");
}
else
{
if (checkBox1.Checked)
{
if (radioButton2.Checked)
{
select += fm.richTextBox1.SelectedText.Length;
marker = select;
select = fm.richTextBox1.Find(str, select, RichTextBoxFinds.MatchCase);
if (select == -1 ||select=marker)
{
marker = start;
select = start;
fm.richTextBox1.SelectionStart = start;
if (select != 0)
fm.richTextBox1.Find(str, 0, select, RichTextBoxFinds.Reverse | RichTextBoxFinds.MatchCase);
MessageBox.Show("找不到" + str, "记事本");
start = marker;
}
}
}
else
{
if (radioButton2.Checked)
{
select+=fm.richTextBox1.SelectedText.Length;
marker = select;
select = fm.richTextBox1.Find(str, select, RichTextBoxFinds.None);
if (select==-1||select=marker)
{
marker = start;
select = start;
fm.richTextBox1.SelectionStart = start;
if (select != 0)
fm.richTextBox1.Find(str, 0, select, RichTextBoxFinds.Reverse | RichTextBoxFinds.None);
MessageBox.Show("找不到" + str, "记事本");
start = marker;
}
}
}
}
}
2023-12-16 05:04:09
164KB
C#记事本
1