473,800 Members | 2,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Default values for user settings

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.Get EnvironmentVari able("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,

Jun 27 '08 #1
8 2034
Personally, I'd simply use %windir%\NOTEPA D.EXE as the default, and
use Environment.Exp andEnvironmentV ariables() to do the expansion on-
demand.

Marc
Jun 27 '08 #2
I don't thinkg the ApplicationSett ings 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.Desig ner" class and hardcode the changes so that it
would look something like this:

[global::System. Configuration.U serScopedSettin gAttribute()]
[global::System. Diagnostics.Deb uggerNonUserCod eAttribute()]
public string TextEditor
{
get
{
return System.Environm ent.GetEnvironm entVariable("wi ndir") + "\\" +
((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.Get EnvironmentVari able("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,



Jun 27 '08 #3
Thanks Marc for the response. I tried %windir%\notepa d.exe however, I'm a
little confused. I still can't get it to return the actual Windows
directory instead of the text "%windir%". I was hoping there was a way to
enter a default setting using the designer which would execute at run-time.
I guess there's no way to do this other than assigning the values
programmaticall y.

"Marc Gravell" <ma**********@g mail.comwrote in message
news:0f******** *************** ***********@x35 g2000hsb.google groups.com...
Personally, I'd simply use %windir%\NOTEPA D.EXE as the default, and
use Environment.Exp andEnvironmentV ariables() to do the expansion on-
demand.

Marc

Jun 27 '08 #4
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******** ********@TK2MSF TNGP03.phx.gbl. ..
>I don't thinkg the ApplicationSett ings 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.Desig ner" class and hardcode the changes so that
it would look something like this:

[global::System. Configuration.U serScopedSettin gAttribute()]
[global::System. Diagnostics.Deb uggerNonUserCod eAttribute()]
public string TextEditor
{
get
{
return System.Environm ent.GetEnvironm entVariable("wi ndir") + "\\" +
((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.Ge tEnvironmentVar iable("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,




Jun 27 '08 #5
Clarks Computing wrote:
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.Get EnvironmentVari able("windir") + "\\NOTEPAD. EXE"

Is there any way to do this at design time, or what is the best way to
handle this?
Make the default a special string ("__DEFAULT_ _" or maybe just ""), test for
it and substitute your dynamic value.

Settings can't be dynamic, they are stored in an xml file.
>
Thanks for any help,

Jun 27 '08 #6
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.SettingsLo aded += this.Settings_S ettingsLoaded;
}

private void Settings_Settin gsLoaded(object sender,
System.Configur ation.SettingsL oadedEventArgs e)
{
if(this.TextEdi tor == string.Empty)
this.TextEditor =
System.Environm ent.ExpandEnvir onmentVariables (@"%windir%\NOT EPAD.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******** ********@TK2MSF TNGP03.phx.gbl. ..
>>I don't thinkg the ApplicationSett ings 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.Desig ner" class and hardcode the changes so that
it would look something like this:

[global::System. Configuration.U serScopedSettin gAttribute()]
[global::System. Diagnostics.Deb uggerNonUserCod eAttribute()]
public string TextEditor
{
get
{
return System.Environm ent.GetEnvironm entVariable("wi ndir") + "\\"
+ ((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.G etEnvironmentVa riable("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,




Jun 27 '08 #7
That's exactly what I was looking for! That did the trick. Thank you so
much.

"Rene" <a@b.comwrote in message
news:em******** ******@TK2MSFTN GP06.phx.gbl...
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.SettingsLo aded += this.Settings_S ettingsLoaded;
}

private void Settings_Settin gsLoaded(object sender,
System.Configur ation.SettingsL oadedEventArgs e)
{
if(this.TextEdi tor == string.Empty)
this.TextEditor =
System.Environm ent.ExpandEnvir onmentVariables (@"%windir%\NOT EPAD.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******* *********@TK2MS FTNGP03.phx.gbl ...
>>>I don't thinkg the ApplicationSett ings 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.Desig ner" class and hardcode the changes so
that it would look something like this:

[global::System. Configuration.U serScopedSettin gAttribute()]
[global::System. Diagnostics.Deb uggerNonUserCod eAttribute()]
public string TextEditor
{
get
{
return System.Environm ent.GetEnvironm entVariable("wi ndir") + "\\"
+ ((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.co m...
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. GetEnvironmentV ariable("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,




Jun 27 '08 #8
Yep, I get it now. I appreciate your response.
"Ben Voigt [C++ MVP]" <rb*@nospam.nos pamwrote in message
news:eT******** ******@TK2MSFTN GP03.phx.gbl...
Clarks Computing wrote:
>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.Ge tEnvironmentVar iable("windir") + "\\NOTEPAD. EXE"

Is there any way to do this at design time, or what is the best way to
handle this?

Make the default a special string ("__DEFAULT_ _" or maybe just ""), test
for it and substitute your dynamic value.

Settings can't be dynamic, they are stored in an xml file.
>>
Thanks for any help,


Jun 27 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
7111
by: Marti | last post by:
Dear everyone, Its my understanding that IE6 now uses a default text-size of "Small" rather than IE5's "Medium". Since I have used relative font-sizes (usually in ems) on all my sites, I am now getting reports of "your fonts are too tiny" from various users. Of course, the sites still look fine if those users set their text-size to medium, but face it -- most people don't even know thats an option.
55
5017
by: Haines Brown | last post by:
I've been setting font-size 1em; as the default in my style sheets. Until now, that seemed to be ok. But now I'm beginning to wonder. My aim is to have an easily readable, but not overly large text when the user uses the default font size in his browser and uses the typical display resolution. I did a reinstall of my friendly browser in a different environment, and I am surprised to find that its default for serif is Times 16 and
0
1762
by: Suzanne | last post by:
Hello experts, I am a VBA newbie. Most of the tricks I apply to my applications I learn from here or google. I couldn't find a solution for the following two things, they both are related to using default user preferences. I hope someone can help me with samples. Question 1: Keeping filter settings I have a form with some unbound comboboxes to do some filtering on the
2
11515
by: syntego | last post by:
We commonly use triggers to log changes to our main tables to historical log tables. In the trigger, we create a concatenated string of the old values by casting them as follows: CAST(O.MYDATE AS CHAR(30)) When directly updating date fields in the main table, the logged value gets saved in the format YYYY-MM-DD as expected.
1
6491
by: logicnet.dk | last post by:
Is it possible to decide where user.config is stored by Properties.Settings.Default.Save? The default location seems to be "C:\Documents and Settings\\Local settings\Application Data\\\" and there are several reasons why I want to change that: 1. I have noticed that the "some random key" part of the path name changed during the development of my application and then the settings were lost. 2. I would prefer that the application version...
4
3596
by: RedHair | last post by:
I developed a Win form with VS.NET 2005 + .NET 2.0 in C# There are some application settings are "User" scope and stored in xxx.settings, I can access them via Settings class and changethem with Settings.Save(); However, if I change and save them then my app will read the change from the user.config , my question is how to access the original default setting?
6
4491
by: AGP | last post by:
VB.NET 2005 I've been working extensively with saving and loading my settings via the My.Settings class. its worked out great except that i cant figure out how to set a default setting that is dynamic. That is to say, the default property changes per user or per machine. As an example, and this is only an example, the default setting for the center of the screen. In the IDE I can set the parameter as ScreenCenter | ...
2
11919
Pittaman
by: Pittaman | last post by:
Hello I am creating some crystal reports (for visual studio 2005) based on the content of certain .NET objects. I'm doing this in .NET 2.0. For one of them I'm using a Cross-table to summarize the information of a bunch of objects. The actual data is numeric. Since these reports are meant to be flexible number formatting must be configured as defined by the requirements. For example, sometimes the values will have to be rounded to 5...
7
1621
by: =?Utf-8?B?Tmljb2xhcw==?= | last post by:
Yes another question about databindings. All my controls are have databindings and works fine for navigating, adding, deleting etc. What I want is when I create a New record have those fields pre-fill with some value stored in my user.setting so the user doesn't have to re-type evrything all the time. Should be so straight forward that I don't get it! The fields are not getting populated with those values.
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10276
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7580
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6813
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.