winform中.用户第一次登陆后输入了用户名及口令.
以二进制形式保存在ini的文件中,
下次登陆的时候可以的从ini文件中找到上次输入的用户名,用户只用输入口令即可.
如果用户更改了用户名,ini文件中存储的信息也要跟着变化..??如何实现????我以前是放在注册表中来实现的...

解决方案 »

  1.   

    用XML来存储吧 ~ 哪还有用INI的了 ~ 
      

  2.   

    .NET中都用XML config,很少用ini了
    查一下System.XML命名空间,.NET操作XML很方便了
      

  3.   

    X      M      L
      

  4.   

    一个是可以用XML,还有就是把用户登录的信息放到数据库中。两种方法都可以,为什么要用INI?
      

  5.   

    用xml存储也可以,具体语法参见坛子上或者msdn
    用ini也行,操作ini得用api,这是一个类,你整理一下就行
    using System;
    using System.Text;
    using System.Collections;
    using System.Runtime.InteropServices;namespace testApplication1 {

    public class IniReader {
    [DllImport("KERNEL32.DLL", EntryPoint="GetPrivateProfileIntA", CharSet=CharSet.Ansi)]
    private static extern int GetPrivateProfileInt(string lpApplicationName, string lpKeyName, int nDefault, string lpFileName);
    [DllImport("KERNEL32.DLL", EntryPoint="WritePrivateProfileStringA", CharSet=CharSet.Ansi)]
    private static extern int WritePrivateProfileString (string lpApplicationName, string lpKeyName, string lpString, string lpFileName);
    [DllImport("KERNEL32.DLL", EntryPoint="GetPrivateProfileStringA",  CharSet=CharSet.Ansi)]
    private static extern int GetPrivateProfileString (string lpApplicationName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName);
    [DllImport("KERNEL32.DLL", EntryPoint="GetPrivateProfileSectionNamesA", CharSet=CharSet.Ansi)]
    private static extern int GetPrivateProfileSectionNames (byte[] lpszReturnBuffer, int nSize, string lpFileName);
    [DllImport("KERNEL32.DLL", EntryPoint="WritePrivateProfileSectionA", CharSet=CharSet.Ansi)]
    private static extern int WritePrivateProfileSection (string lpAppName, string lpString, string lpFileName);
    public IniReader(string file) {
    Filename = file;
    }
    public string Filename {
    get {
    return m_Filename;
    }
    set {
    m_Filename = value;
    }
    }
    public string Section {
    get {
    return m_Section;
    }
    set {
    m_Section = value;
    }
    }
    public int ReadInteger(string section, string key, int defVal) {
    return GetPrivateProfileInt(section, key, defVal, Filename);
    }
    public int ReadInteger(string section, string key) {
    return ReadInteger(section, key, 0);
    }
    public int ReadInteger(string key, int defVal) {
    return ReadInteger(Section, key, defVal);
    }
    public int ReadInteger(string key) {
    return ReadInteger(key, 0);
    }
    public string ReadString(string section, string key, string defVal) {
    StringBuilder sb = new StringBuilder(MAX_ENTRY);
    int Ret = GetPrivateProfileString(section, key, defVal, sb, MAX_ENTRY, Filename);
    return sb.ToString();
    }
    public string ReadString(string section, string key) {
    return ReadString(section, key, "");
    }
    public string ReadString(string key) {
    return ReadString(Section, key);
    }
    public long ReadLong(string section, string key, long defVal) {
    return long.Parse(ReadString(section, key, defVal.ToString()));
    }
    public long ReadLong(string section, string key) {
    return ReadLong(section, key, 0);
    }
    public long ReadLong(string key, long defVal) {
    return ReadLong(Section, key, defVal);
    }
    public long ReadLong(string key) {
    return ReadLong(key, 0);
    }
    public byte[] ReadByteArray(string section, string key) {
    try {
    return Convert.FromBase64String(ReadString(section, key));
    } catch {}
    return null;
    }
    public byte[] ReadByteArray(string key) {
    return ReadByteArray(Section, key);
    }
    public bool ReadBoolean(string section, string key, bool defVal) {
    return Boolean.Parse(ReadString(section, key, defVal.ToString()));
    }
    public bool ReadBoolean(string section, string key) {
    return ReadBoolean(section, key, false);
    }
    public bool ReadBoolean(string key, bool defVal) {
    return ReadBoolean(Section, key, defVal);
    }
    public bool ReadBoolean(string key) {
    return ReadBoolean(Section, key);
    }
    public bool Write(string section, string key, int value) {
    return Write(section, key, value.ToString());
    }
    public bool Write(string key, int value) {
    return Write(Section, key, value);
    }
    public bool Write(string section, string key, string value) {
    return (WritePrivateProfileString(section, key, value, Filename) != 0);
    }
    public bool Write(string key, string value) {
    return Write(Section, key, value);
    }
    public bool Write(string section, string key, long value) {
    return Write(section, key, value.ToString());
    }
    public bool Write(string key, long value) {
    return Write(Section, key, value);
    }
    public bool Write(string section, string key, byte [] value) {
    if (value == null)
    return Write(section, key, (string)null);
    else
    return Write(section, key, value, 0, value.Length);
    }
    public bool Write(string key, byte [] value) {
    return Write(Section, key, value);
    }
    public bool Write(string section, string key, byte [] value, int offset, int length) {
    if (value == null)
    return Write(section, key, (string)null);
    else
    return Write(section, key, Convert.ToBase64String(value, offset, length));
    }
    public bool Write(string section, string key, bool value) {
    return Write(section, key, value.ToString());
    }
    public bool Write(string key, bool value) {
    return Write(Section, key, value);
    }
    public bool DeleteKey(string section, string key) {
    return (WritePrivateProfileString(section, key, null, Filename) != 0);
    }
    public bool DeleteKey(string key) {
    return (WritePrivateProfileString(Section, key, null, Filename) != 0);
    }
    public bool DeleteSection(string section) {
    return WritePrivateProfileSection(section, null, Filename) != 0;
    }
    public ArrayList GetSectionNames() {
    try {
    byte[] buffer = new byte[MAX_ENTRY];
    GetPrivateProfileSectionNames(buffer, MAX_ENTRY, Filename);
    string [] parts = Encoding.ASCII.GetString(buffer).Trim('\0').Split('\0');
    return new ArrayList(parts);
    } catch {}
    return null;
         }
    private string m_Filename;
    private string m_Section;
    private const int MAX_ENTRY = 32768;
    }
    }
      

  6.   

    谢谢楼上的兄弟们..我先看看xml的帮助.试一下.