remember me information winform c#

28 Mar

You can use the ConfigurationManager Class to manage your application’s settings.

you can use this function to add new Keys to your configuration file:




public bool setSetting(string pstrKey, string pstrValue)
    Configuration objConfigFile =
    bool blnKeyExists = false;

    foreach (string strKey in objConfigFile.AppSettings.Settings.AllKeys)
        if (strKey == pstrKey)
            blnKeyExists = true;
            objConfigFile.AppSettings.Settings[pstrKey].Value = pstrValue;
    if (!blnKeyExists)
        objConfigFile.AppSettings.Settings.Add(pstrKey, pstrValue);
    return true;

and then save up your username (for example)

write this code on login button click event

if (chkrember.Checked==true)
setSetting(“username”, txtloginid.Text);
setSetting(“mypasswd”, txtpassword.Text);

setSetting(“username”, “”);
setSetting(“mypasswd”, “”);


On Load write this code

txtLogin.Text = ConfigurationManager.AppSettings[“username”];
txtPassword.Text = ConfigurationManager.AppSettings[“mypasswd”];
if( txtLogin.Text.Length>0){
chkrember.Checked = true;

Once your application starts up, you can read the information you saved earlier from yourConfigurationManager
txtloginid.Text = ConfigurationManager.AppSettings["username"];

txtpassword.Text = ConfigurationManager.AppSettings["mypassword"];
Click on Project properties and add username & mypassword 

Leave a comment

Posted by on March 28, 2013 in WinForm



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: