2011-05-20 71 views
2

我試圖達到開始 - >控制面板 - >區域和語言選項 - >自定義 - >十進制符號 並從用c#編寫的Windows窗體應用程序中更改該值。我尋找不同的解決方案,從這樣的:用c#在電腦上達到控制面板的功能#

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

,因爲這些System.Globalization或文化的東西不能,如果用戶手動更改只是價值他/她的電腦上看到的。

我怎樣才能解決這個問題,請幫助..

+0

的設置是在註冊表中。這將有助於:http://technet.microsoft.com/en-us/library/cc785785(WS.10).aspx – hsmiths 2011-05-21 00:29:39

+0

如何從代碼中獲取?有沒有圖書館要包括? – dnur 2011-05-21 07:43:01

+0

請參閱下面的示例 – hsmiths 2011-05-21 14:47:50

回答

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