سؤال

I'm using Visual Studio 2010 where I have a project, called Utilities, containing my settings.settings file which I want to access from other projects in the solution.

In another project, I want to let the user manage the settings in a Windows Form using PropertyGrid. I also want to customize it using System.ComponentModel settings. I've tried to apply the ComponentModel settings such as DescriptionAttribute in the Settings.Designer.cs file which worked, but as it say in the comments of the file, the changes to that file when regenerated.

So my questions is as follows:

  1. How do I access the Properties.Settings from another project?
  2. How do I customize the PropertyGrid without changing the Settings.Designer.cs file?
  3. As mentioned, I let the user manage the settings from a form. However, I want to restore the values when the users presses Cancel button. How do I do that?
هل كانت مفيدة؟

المحلول

  1. Set the Access Modifier in the setting designer to public (default is internal)

  2. I would go with a wrapper-class for your Settings (just a lot of attribute-decorated properties with get/set pointing to the original settings). This code could be auto-generated from the Settings.Designer.cs file.

  3. Save the previous settings, e.g. via serialization (binary or xml), to a variable. Then you can restore it by setting the properties to the saved value.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top