[英]SharedPreferences but on c# Windows Form Apps C# Visual Studio
我正在創建一個簡單的消息程序,您可以在其中與其他人交談。
目前,我正在登錄屏幕上工作,我想創建一個“記住我”選項,它將在您下次進入應用程序時保存您的憑據。 我使用 android Studio 和 Unity 進行了一些工作,它們都使用了名為SharedPreferences
的東西,我使用了它,它很棒。 所以我想知道 C# 是否有SharedPreferences
以及如何在 Windows 表單應用程序上使用它。
接受任何幫助。
在winforms中,我們通常使用Settings
來保存用戶設置信息。
要達到要求,可以參考以下步驟:
3.試試下面的代碼:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// Save the current state of the checkbox
Properties.Settings.Default.cb = checkBoxRememberMe.Checked;
Properties.Settings.Default.str = textBox1.Text;
Properties.Settings.Default.Save();
}
private void Form1_Load(object sender, EventArgs e)
{
// load checkbox state from settings
checkBoxRememberMe.Checked = Properties.Settings.Default.cb;
textBox1.Text = Properties.Settings.Default.str;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.