c# 简单的一个记事本

自己学习了c++面向对象的程序设计,为了学习和熟悉可视化编程风格和方法,特别是熟悉使用Windows的编程环境和风格。综合运用相关控件,在C++思想的基础之上,自己用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--;
     ...

posted on 2009-08-31 22:59  9号  阅读(371)  评论(0编辑  收藏  举报

导航