首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

新手!怎样实现多文本猜想输入和历史记录

2013-01-26 
新手求助!怎样实现多文本猜想输入和历史记录?我现在有多个textbox文本框,想各自文本框记住各自的内容 ,下

新手求助!怎样实现多文本猜想输入和历史记录?
我现在有多个textbox文本框,想各自文本框记住各自的内容 ,下次输入的时候只会弹出此文本框输入过的内容,而不是所有内容      我现在就是会弹出所有内容给我选择     怎么实现单独记录    在线等!!!!!!!!! textbox
[解决办法]
用反射,或者form.contros枚举所有文本框,接管change事件,变化就保存自己,读取的时候,也只读自己:如
form_load()
{
  foreach( control c in this.controls)
{
 if( c as textbox !=null)
{
    c.text=Load(路径+c.name+".txt"}
}
}
[解决办法]
可以用ini文件,文件标题对应文本框名字,其中每一个小项对应内容。比如
[TextBox1]
Text1=12
Text2=13
[TextBox2]
Text1=14
Text2=15
可以用
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string defVal, StringBuilder retVal, int size, string filePath); 
[DllImport("kernel32")] 
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath); 来读取。为了提高效率你应该不存在数据库中,反应太慢。而且查找时最好用字典
[解决办法]


//初始化数据
 private void InitialData()
        {
            string[] keys = INIGetAllItemKeys(".\\config.ini", "textBox2");
            AutoCompleteStringCollection ac = new AutoCompleteStringCollection();
            ac.AddRange(keys);
            textBox2.AutoCompleteCustomSource = ac;
        }
private void textBox2_TextChanged(object sender, EventArgs e)
        {
            TextBox tb=sender as TextBox;
            WritePrivateProfileString(tb.Name, tb.Text, tb.Text, ".\\config.ini");
        }
 /// <summary>  
        /// 获取INI文件中指定节点(Section)中的所有条目的Key列表  网上找的
        /// </summary>  
        /// <param name="iniFile">Ini文件</param>  
        /// <param name="section">节点名称</param>  
        /// <returns>如果没有内容,反回string[0]</returns>  
        public static string[] INIGetAllItemKeys(string iniFile, string section)
        {
            string[] value = new string[0];
            const int SIZE = 1024 * 10;

            if (string.IsNullOrEmpty(section))
            {


                throw new ArgumentException("必须指定节点名称", "section");
            }
            char[] chars = new char[SIZE];
            uint bytesReturned = GetPrivateProfileString(section, null, null, chars, SIZE, iniFile);
            if (bytesReturned != 0)
            {
                value = new string(chars).Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
            }
            chars = null;
            return value;
        }  


把文本框的AutoCompleteSource属性设置为CustomSource,把AutoCompleteMode属性设置为SuggestAppend,只实现了基本需求,具体要求自己改吧。
[解决办法]
引用:
这里必须自己写程序了,不能采用文本框的属性设置是否保留历史记录了,web应该需要在获得焦点事件中结合ajax完成,winform里面的话也是在获得焦点的事件中编写代码


在空间失去焦点的时候记录,标示一次输入完成了

热点排行