c# 简单的一个记事本
自己在做的时候,就是有一个查找的方法,不知道怎么做出那个窗口,历经数日,终于做出来了,以下就是查找部分的源代码,
private void BFind_Click(object sender, EventArgs e) {
//设置起始的位置
int start,end;
if (textBox1.Text.Length==0)
{
MessageBox.Show("出错了!要查找的字符不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
//是否是选择向上或向下,来调用不同的搜索函数
if (radioButtonDown.Checked)
{ if (location == -1)
start = 0;
else
{
start = location;
}
if (checkBox1.Checked)
{
string input, modify;
input = textBox1.Text.ToUpper();
modify = textBox.Text.ToUpper();
location = modify.IndexOf(input, start);
if (location == -1)
{
//显示未找到指定字符串
MessageBox.Show("找不到 \"" + textBox1.Text + "\"", "记事本", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
//标记出字符串的位置
this.textBox.Select(location, textBox1.Text.Length);
this.textBox.Focus();
if (location >= textBox.Text.Length)
{
MessageBox.Show("找不到 \"" + textBox1.Text + "\"", "记事本", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
location++;
}
}
}
else
{ location = textBox.Text.IndexOf(textBox1.Text, start);//查找
if (location == -1)
{
//显示未找到指定字符串
MessageBox.Show("找不到 \"" + textBox1.Text + "\"", "记事本", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
出字符串的位置
this.textBox.Select(location, textBox1.Text.Length);
this.textBox.Focus();
{
MessageBox.Show("找不到 \"" + textBox1.Text + "\"", "记事本", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
location++;
}
}
}
}
else
if (radioButtonUp.Checked)
{
if (location == -1)
end = textBox.Text.Length;
else
end = location
if (checkBox1.Checked)
{
string input, modify;
modify = textBox.Text.ToUpper();//设置中间量转换大小写函数,不直接对它窗口进行操作
if (location == -1)
{
//显示未找到指定字符串
MessageBox.Show("找不到 \"" + textBox1.Text + "\"", "记事本", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
if (location ==0)
{
MessageBox.Show("找不到 \"" + textBox1.Text + "\"", "记事本", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
//标记出字符串的位置
this.textBox.Select(location, textBox1.Text.Length);
this.textBox.Focus();
}
location--;
}
}
else
{
location = textBox.Text.LastIndexOf(textBox1.Text, end);//查找
if (location == -1)
{
//显示未找到指定字符串
MessageBox.Show("找不到 \"" + textBox1.Text + "\"", "记事本", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
if (location == 0)
{
MessageBox.Show("找不到 \"" + textBox1.Text + "\"", "记事本", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
//标记出字符串的位置
this.textBox.Select(location, textBox1.Text.Length);
this.textBox.Focus
}
location--;
...