-1

So I was having trouble adding a new App.Config userSettings. Without any knowledge. I tried to set the configuration directly in the app.config HML. Files get overwritten. It stays in App.Config but it does not show up in the Settings.Designer or IntelliSense. I know it should show up in the IntelliSense because the configured userSettings that are already present do.

How do you correctly configure a user setting?

Maybe, this question is a duplicate of this: How to save application settings in a Windows Forms Application?

I guess I would accept that, but it was difficult to find the answer to the question starting from the point of view I started with. I think that there are allot of well meaning souls like me that try to directly edit the app.config file to achieve this and wonder why they get nowhere fast. These askers are are unsure where to find the correct answer. I also suspect that other well meaning souls that answer their questions assuming that the questioner was asking from a prospective where they knew the answer to this question. This of course makes understanding difficult to reach for the original seeker of knowledge.

amalgamate
  • 2,200
  • 5
  • 22
  • 44
  • There may actually be some cause to say something is too easy, (see https://meta.stackoverflow.com/q/296245/1060900) but I feel that the value in this question is that it clears up miscommunications that I found looking through Stack Overflow. – amalgamate Aug 22 '19 at 20:24

1 Answers1

1

Answer: I checked Microsoft to learn more and found this link:

https://learn.microsoft.com/en-us/dotnet/framework/winforms/advanced/how-to-create-a-new-setting-at-design-time

which says this:

  1. Open Visual Studio.
  2. In Solution Explorer, right-click your project node and choose Properties.
  3. In the Properties page, select the Settings tab.
  4. In the Settings designer, set the Name, Value, Type, and Scope for your setting. Each row represents a single setting.

I found that I could even use custom types like my enum, which vs will convert from a string in the HML.

Now this procedure populates App.config and Settings.Designer.cs with the setting for you. It shows up in IntelliSense too. Fantastic!

Note: The settings can also be accessed by Settings.Settings.

Now I have noticed, since I continually seem to want to get under the hood and do things in an undocumented way: It is possible to directly edit the Settings.Settings file. Don't do that either, That will get you pretty far but the settings you configure there will not persist when you build.

amalgamate
  • 2,200
  • 5
  • 22
  • 44