Now that I am taking a second look at your problem, what about creating a
"partial class Settings"?
This is actually built in .Net, all you do is go to the settings designer
and click on the "View Code" toolbar button. This will automatically
generate the class for you (it can't get any easier)!
Then you can make the changes in the automatically generated class so that
it looks something like the following:
internal sealed partial class Settings
{
public Settings()
{
this.SettingsLoaded += this.Settings_SettingsLoaded;
}
private void Settings_SettingsLoaded(object sender,
System.Configuration.SettingsLoadedEventArgs e)
{
if(this.TextEditor == string.Empty)
this.TextEditor =
System.Environment.ExpandEnvironmentVariables(@"%w indir%\NOTEPAD.EXE");
}
}
That's it, if the value of "TextEditor" is empty (this should be your
default value) then you set it to the proper value. After that, the value
should be hardcoded to the exact path.
Does this help you?
"Clarks Computing" <Cl*************@nospam.please.comwrote in message
news:48***********************@roadrunner.com...
Thanks, but what a pain! I thought this would be such an easy thing to
do, but it doesn't seem to be the case. What would you suggest instead of
the settings class? Is there an easier way to manage user settings for a
small project which is what I'm working on?
"Rene" <a@b.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>>I don't thinkg the ApplicationSettings class is able to evaluate the
expression and return the correct value.
Then only way I see that you can accomplish something like what you want
is to hack the "Settings.Designer" class and hardcode the changes so that
it would look something like this:
[global::System.Configuration.UserScopedSettingAttr ibute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttr ibute()]
public string TextEditor
{
get
{
return System.Environment.GetEnvironmentVariable("windir" ) + "\\"
+ ((string)(this["TextEditor"]));
}
set
{
this["TextEditor"] = value;
}
}
I think thissolution is reeeeeeeeeally cheese. For consistnecy, I guess
you can add code to the "set" accsesor so that get and set are consistent
(the set and get return the same type of string with "windir" as the
prefixed path).
Keep in mind that the designer will overwrite everything every time you
make a change so you will have to constantly remember to update the file.
I would't recommend going this way but if you have no other choose well
there is an option.....
"Clarks Computing" <Cl*************@nospam.please.comwrote in message
news:48**********************@roadrunner.com...
>>Hi all,
Question regarding the settings feature in Visual C# 2008. Let's say I
create a user setting called TextEditor in the settings designer. I
realize
that I can type a string value such as NOTEPAD.EXE in the Value column.
However, what if I want to make the default value something like the
following:
Environment.GetEnvironmentVariable("windir") + "\\NOTEPAD.EXE"
Is there any way to do this at design time, or what is the best way to
handle this?
Thanks for any help,