日期:2014-05-17  浏览次数:20773 次

新手求助!怎样实现多文本猜想输入和历史记录?
我现在有多个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))