简体   繁体   中英

How i can save settings to the application Settings?

I created a new cell called it MySettings

MySettings

The type is string the scope is user.

And in this place i want to store the last selected path:

private void btnDirectory_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog MyDialog = new FolderBrowserDialog();
            MyDialog.SelectedPath = lblDirectoryName.Text;

            if (MyDialog.ShowDialog() == DialogResult.OK)
            {
                lblDirectoryName.Text = MyDialog.SelectedPath;
            }
        }

Right after the line

MyDialog.SelectedPath = lblDirectoryName.Text;

I want to store the MyDialog.SelectedPath to MySettings I tried to type: Properties.Settings. but i have there some options the first Default. But where is MySettings ?

And where and how i load back the saved settings ?

 if (MyDialog.ShowDialog() == DialogResult.OK)
  {
    lblDirectoryName.Text = MyDialog.SelectedPath;
    Properties.Settings.Default.MySettings=MyDialog.SelectedPath;
    Properties.Settings.Default.Save();
  }

You can retrieve the store/saved value as following:

MyDialog.SelectedPath=Properties.Settings.Default.MySettings;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM