dnur
dnur

Reputation: 709

Reach control panel's features on the pc with c#

I try to reach Start->Control Panel->Regional and Language Options->Customize->Decimal Symbol and change of that value from windows forms app written in c#. I search different solution from this :

    System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentCulture;
string decimalSeparator = ci.NumberFormat.CurrencyDecimalSeparator;

because these System.Globalization or culture things can't see if the user change just that value manually on his/her computer.

How can I handle this problem, please help..

Upvotes: 2

Views: 412

Answers (1)

hsmiths
hsmiths

Reputation: 1307

Here is an example of how to change the decimal character and then restore the original.

using System;
using System.Security.Permissions;
using Microsoft.Win32;

[assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum, ViewAndModify="HKEY_CURRENT_USER")]

namespace sampleProgram
{
    public class sampleClass
    {
        static void Main()
        {
            // open the registry key holding control panel international settings
            using (RegistryKey international = Registry.CurrentUser.OpenSubKey("Control Panel\\International", true))
            {

                // get and display the current decimal character
                string original_sDecimal = international.GetValue("sDecimal").ToString();
                Console.WriteLine("original sDecimal='" + original_sDecimal + "'");
                Console.WriteLine("Press enter:");
                Console.ReadLine();

                // temporarily change the decimal character
                string alternate_sDecimal = "@";
                international.SetValue("sDecimal", alternate_sDecimal);
                Console.WriteLine("alternate sDecimal='" + international.GetValue("sDecimal").ToString() + "'");
                Console.WriteLine("Press enter:");
                Console.ReadLine();

                // put back the original decimal character
                international.SetValue("sDecimal", original_sDecimal);
                Console.WriteLine("restored original sDecimal='" + international.GetValue("sDecimal").ToString() + "'");
                Console.WriteLine("Press enter:");
                Console.ReadLine();
            }
        }
    }
}

Look here for more information on this topic: http://msdn.microsoft.com/en-us/library/microsoft.win32.registrykey(v=VS.90).aspx

Upvotes: 2

Related Questions