views:

69

answers:

1

A user wants me to create an app that does something everything he presses the X key.

Now he asked me to make it so he can change what key he has to press. Maybe he wants X key today, maybe C key tomorrow.

How can I easily do this in C#? What is the best way?

+4  A: 

You can use .Net's Application Settings feature.

Go to the Settings tab in Project Properties and add a setting.
You can then access it in code by writing Properties.Settings.Default.MySettingName.

SLaks
sounds cool, where does it save the setting? in the .exe? or registry?
matt
I'm trying to access my propety but all I see in the intellisense is: Default, Equals, Reference Equals. What am I doing wrong?
Serg
@Sergio: I forgot to mention that you need to add `.Default.`; I fixed the answer.
SLaks
It saves it to an XML file, usually the name of your app.exe.config. You reference it using Settings.Default.MySettingName. The problem is, I don't think you can write to it using the Settings class. I don't think it preserves the changes you make to it in code....
BFree
OK, I just double checked. After you make a change, be sure to call Settings.Default.Save();
BFree