Csharp 讀寫文件內容搜索自動彈出 AutoCompleteMode

简介: using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsStyle
{
    public partial class LoginForm : Form
    {
        protected string fileName = "login.dat";
        string path = Directory.GetCurrentDirectory();
        string file;
        /// <summary>
        /// 
        /// </summary>
        public LoginForm()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 2011-11-2 塗聚文
        /// 缔友计算机信息技术有限公司
        /// 加载窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LoginForm_Load(object sender, EventArgs e)
        {
            file = path + "\\" + fileName;

            textBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
            if (File.Exists(file))//文件是否存在
            {
                StreamReader sr = new StreamReader(file, true);
                string str = sr.ReadLine();
                while (str != null) //判断是否为空
                {
                    if (!this.textBox1.AutoCompleteCustomSource.Contains(str))//记录是否存
                    {
                        this.textBox1.AutoCompleteCustomSource.Add(str);//不存在添加
                    }
                    str = sr.ReadLine();
                }
                sr.Close();
            }
        }
        /// <summary>
        /// 写入
        /// 涂聚文
        /// 缔友计算机信息技术有限公司
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            file = path + "\\" + fileName;
            textBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
            if (File.Exists(file))
            {
               if(!this.textBox1.AutoCompleteCustomSource.Contains(this.textBox1.Text.Trim()))//判断记录是否存在
               {
                   StreamWriter sw=new StreamWriter(file,true);
                   sw.WriteLine(this.textBox1.Text.Trim()); //写入记录
                   sw.Close();//关闭文件流
                   if(!this.textBox1.AutoCompleteCustomSource.Contains(this.textBox1.Text))
                   {
                       this.textBox1.AutoCompleteCustomSource.Add(this.textBox1.Text);
                   }
               }
            }
            this.Close();

        }
    }
}


目录
相关文章
|
10月前
|
Java
Java实现1.指定关键字搜索 2.指定后缀名搜索 3.文件/文件夹复制
Java实现1.指定关键字搜索 2.指定后缀名搜索 3.文件/文件夹复制
52 1
|
XML Java 数据格式
myeclipse 搜索 快捷键 搜索类 搜索jsp 搜索整个工程
ctrl+shift+t :搜索类 (好像和ctrl+shift+r是一样的效果) ctrl+shift+f :搜索jsp ctrl+f这个不解释了 search菜单下的search (ctrl + H)(感觉这个用处不大) 经常使用!我的项目有600多M,没办法呀。
717 0
|
1天前
|
Linux
find 文件目录搜索工具
`find` 是 Linux 系统中功能强大且灵活的文件搜索工具,支持多种复杂条件。基本用法:`find /path/to/search -name &quot;filename&quot;` 查找指定文件;`-delete` 删除找到的文件;`-size` 根据文件大小查找;`-mtime` 根据修改时间查找;`-empty` 查找空文件或目录。适用于系统维护和日常文件管理。
18 8
|
缓存 Python Shell
Python模块搜索路径
当一个名为 spam 的模块被导入的时候,解释器首先寻找具有该名称的内置模块。如果没有找到,然后解释器从 sys.path 变量给出的目录列表里寻找名为 spam.py 的文件。sys.path 初始有这些目录地址: 包含输入脚本的目录(或者未指定文件时的当前目录)。
|
iOS开发
xcode中使用正则表达式来搜索替换代码
有这样的需求: 类似于 GLOBAL_STR(@"请继续添加"); 这样的代码,需要批量修改为: GLOBAL_STR(@"请继续添加", nil); 这里使用普通的查找替换不能够达到目的,需要用到正则表达式: GLOBAL_STR(.*); 替换文本的正则: GLOBAL_STR(.$1,nil); xcode的查找替换选项里面选择regular expression,使用上面的正则即可解决问题。
1406 0
|
安全 测试技术 Windows
关于DLL搜索路径顺序的一个问题
DLL的动态链接有两种方法。一种是加载时动态链接(Load_time dynamic linking)。Windows搜索要装入的DLL时,按以下顺序:应用程序所在目录→当前目录→Windows SYSTEM目录→Windows目录→PATH环境变量指定的路径。
1656 0
|
Linux 数据库
文件的搜索
在使用Linux系统时,有时会因为文件创建时间很久,而记不得全全名,只能记得模糊的几个关键字时,就可以使用文件查找命令来进行快速搜索。Linux提供最常用的搜索方有两个工具locate与find。不过在日常中还是使用find比较多,因为他具有时效性。
929 0
|
SQL Windows
搜索路径
搜索路径
155 0
Google 代码搜索
 今天在CSDN上看到的消息,google推出了CodeSearch的服务,上去一测试,吓死我了! 代码的秘密全无了! http://www.google.com/codesearch/ 你可以试试你的代码看看! 比如:搜索以下:on error resu...
909 0