c# - 使用 C# 在 pc 上实现控制面板的功能

标签 c#

我尝试到达“开始”->“控制面板”->“区域和语言选项”->“自定义”->“十进制符号” 并从用 c# 编写的 Windows 窗体应用程序更改该值。我从中搜索不同的解决方案:

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

因为这些 System.Globalization 或文化事物无法看到用户是否仅在他/她的计算机上手动更改该值。

我该如何处理这个问题,请帮忙..

最佳答案

这里是一个例子,说明如何改变十进制字符,然后恢复原来的。

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

关于c# - 使用 C# 在 pc 上实现控制面板的功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6078432/

相关文章:

c# - 如何使用 Monodevelop 为 iPhone 动态创建 UI

c# - 根据单词列表搜索短语列表并计算出现次数

c# - 我应该测试方法不会抛出异常吗?

c# - 使用 Structure Map 替换泛型类型参数中的抽象类型

在现有 LinkedList<T> 中添加新项的 C# 最佳方法?

c# - 为什么当我在 Visual Studio 中运行该程序时,我的窗体看起来不一样?

c# - 为什么递归构造函数调用会使无效的 C# 代码编译?

C# |为程序添加密码保护

C# KeyDown事件多个Key加ControlKey

c# - 返回 IList<IList<T>>