簡體   English   中英

SharedPreferences 但在 c# Windows 表單應用程序 C# Visual Studio

[英]SharedPreferences but on c# Windows Form Apps C# Visual Studio

我正在創建一個簡單的消息程序,您可以在其中與其他人交談。

目前,我正在登錄屏幕上工作,我想創建一個“記住我”選項,它將在您下次進入應用程序時保存您的憑據。 我使用 android Studio 和 Unity 進行了一些工作,它們都使用了名為SharedPreferences的東西,我使用了它,它很棒。 所以我想知道 C# 是否有SharedPreferences以及如何在 Windows 表單應用程序上使用它。

接受任何幫助。

在winforms中,我們通常使用Settings來保存用戶設置信息。

要達到要求,可以參考以下步驟:

1.單擊“項目”並選擇“設置屬性...”,然后選擇“設置” 在此處輸入圖像描述

2.在“設置”中添加新設置在此處輸入圖像描述

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM