RSS

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:

surveyform

 

 

public bool setSetting(string pstrKey, string pstrValue)
{
    Configuration objConfigFile =
        ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    bool blnKeyExists = false;

    foreach (string strKey in objConfigFile.AppSettings.Settings.AllKeys)
    {
        if (strKey == pstrKey)
        {
            blnKeyExists = true;
            objConfigFile.AppSettings.Settings[pstrKey].Value = pstrValue;
            break;
        }
    }
    if (!blnKeyExists)
    {
        objConfigFile.AppSettings.Settings.Add(pstrKey, pstrValue);
    }
    objConfigFile.Save(ConfigurationSaveMode.Modified);
    ConfigurationManager.RefreshSection("appSettings");
    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);

}
else
{
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 

remberme
Advertisements
 
Leave a comment

Posted by on March 28, 2013 in WinForm

 

Tags:

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

 
%d bloggers like this: