做好一个数据库系统一开始需要用户链接数据库,比如要输入密码啊,要输入数据库名称啥的还行但是时间长了,有点麻烦,我就想做一个功能,类似QQ登陆保存用户名 保存密码一样的比如在用户名的,或者数据库名字后面有一个checkBox,选择以后,以后再登陆就不用再输入了,就能直接登陆啥的了-----------------------------------------就是为了达到找个功能,我没啥思路,也没啥办法,还请高手赐教一下,谢谢了!!

解决方案 »

  1.   

    控件布局,相信你没有问题了。然后判断CheckBox的属性,如果check,那么写入配置文件,可以使用ConfigurationManager类完成。具体使用参考MSND帮助。然后启动时,判断check是否是自动登录,如果是,就读取配置文件中的用户登录信息。
    就是这样了。
      

  2.   

      GetPrivateProfileString()
      WritePrivateProfileString()
      

  3.   


    using System;
    using System.Data;
    using System.IO;
    using System.Text;public void WriteFile(string content, string fileSavePath)
    {
               if (System.IO.File.Exists(fileSavePath))
            {
                System.IO.File.Delete(fileSavePath);
            }
            using (System.IO.FileStream fs = System.IO.File.Create(fileSavePath)) 
            {
                byte[] info = new System.Text.Encoding.GetEncoding("gb2312").GetBytes(content);   //防止乱码
                fs.Write(info, 0, info.Length);
            }
    }
    public string ReadFile(string fileOpenPath)
    {
               if (!System.IO.File.Exists(fileOpenPath))
            {
                return null;
            }
            using (System.IO.StreamReader sr = System.IO.File.OpenText(fileOpenPath)) 
            {
                return  sr.ReadToEnd().ToString();
            }
    }上面是文件读写代码,若要加密,就只有自己写加密方式了
      

  4.   

    我在GOOGLE上查到一些操作INI的文章,我先下学习一下吧谢谢了,不过哪位老大写一下教程,我会学更快的撒
      

  5.   

    就把你的登陆信息写进一个文件中,下次开启时判断checkbox的属性是否读出文件中保存的内容上面已经有读写文件的代码,LZ可以参考
      

  6.   

    用Settings应该是最简单的了把  
      

  7.   

    操作XML文件
    或config文件保存数据
    XML文件操作
      

  8.   

    搞了一下,INI可以搞定了,下一步就是加密解密 以及checkbox的ConfigurationManager了using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.Runtime.InteropServices;using System.Text;namespace INI3{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        [DllImport("kernel32")]        private static extern long WritePrivateProfileString(string section,string key, string val, string filePath);        [DllImport("kernel32")]        private static extern int GetPrivateProfileString(string section,string key, string def, StringBuilder retVal,int size, string filePath);        private void button1_Click(object sender, EventArgs e)        {            openFileDialog1.ShowDialog();            textBox1.Text = openFileDialog1.FileName;        }        private void button2_Click(object sender, EventArgs e)        {            string FileName = textBox1.Text;            string section = textBox2.Text;            string key = textBox3.Text;            string keyValue = textBox4.Text;            WritePrivateProfileString(section, key, keyValue, FileName);            MessageBox.Show("成功写入INI文件!", "信息");        }        private void button3_Click(object sender, EventArgs e)        {              StringBuilder temp = new StringBuilder (255) ;              string FileName = textBox1.Text;              string section = textBox2.Text;              string key = textBox3.Text;              int i = GetPrivateProfileString(section,key,"无法读取对应数值!",temp,255,FileName);              //显示读取的数值              textBox4.Text = temp.ToString();        }    }}