其他分享
首页 > 其他分享> > WPF 应用 - 使用 Properties.Settings 保存客户端密码

WPF 应用 - 使用 Properties.Settings 保存客户端密码

作者:互联网

1. 先在项目的 Settings.settings 新建需要的字段和类型

有需要还可设置初始默认值

2. 启动客户端时,获取 Properties.Settings 的属性值

public void Construct()
{
    if (Properties.Settings.Default.IsRemebered)
    {
        user.Text = Properties.Settings.Default.UserName;
        passwd.Password = Properties.Settings.Default.Password;
        isRemember.IsChecked = true;
    }
}

3. 登录时,保存用户输入的信息到 Properties.Settings

private void Login_Click(object sender, RoutedEventArgs e)
{
    if (isRemember.IsChecked == true)
    {
        Properties.Settings.Default.UserName = user.Text;
        Properties.Settings.Default.Password = passwd.Password;
    }
    
    Properties.Settings.Default.IsRemebered = isRemember.IsChecked ;
    Properties.Settings.Default.Save();
}

另外:

标签:Settings,Default,IsChecked,WPF,Password,Properties,isRemember
来源: https://www.cnblogs.com/MichaelLoveSna/p/14486219.html