我尝试访问开始 - >控制面板 - >区域和语言选项 - >自定义 - >十进制符号 并从用c#编写的Windows窗体应用程序更改该值。我从中搜索不同的解决方案:
System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentCulture;
string decimalSeparator = ci.NumberFormat.CurrencyDecimalSeparator;
因为这些System.Globalization或文化事物无法看到用户是否在他/她的计算机上手动更改了该值。
我该如何处理这个问题,请帮助..
答案 0 :(得分:2)
以下是如何更改小数字符然后恢复原始字符的示例。
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();
}
}
}
}
在此处查看有关此主题的更多信息:http://msdn.microsoft.com/en-us/library/microsoft.win32.registrykey(v=VS.90).aspx