6 Replies - 1870 Views - Last Post: 21 May 2011 - 06:58 AM Rate Topic: -----

#1 dnur   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-May 11

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

Posted 21 May 2011 - 02:48 AM

Hi, 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?

Is This A Good Question/Topic? 0
  • +

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

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6536
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

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

Posted 21 May 2011 - 04:55 AM

You haven't really described the problem. What is your end goal, not the path you are trying to take to get there?

Trying to 'reach' the control panel is basically pointless if you think you are going to read the information in it. It doesn't contain information all the time. It reads the current System.Globaliation values when it launches, it allows you to change those values, then it evaporates when you close the control panel.

Are you trying to make sure you use the right currency separator, even if the user changes it after you launched your application? If that is the case use a property instead of a field.

string decimalSeparator
{
     get { return ci.NumberFormat.CurrencyDecimalSeparator;
}



If you're just trying to format/display currency correctly, don't do the formatting yourself: let the OS do that for you. That's what the string.format method is for.
c Currency {0:c} $1.42 -$12,400

This is probably the de factor resource for using String.Format()
http://blog.stevex.n...ting-in-csharp/
Was This Post Helpful? 0
  • +
  • -

#3 dnur   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-May 11

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

Posted 21 May 2011 - 05:03 AM

my goal is reach and change just that value. Something like that :

ci.NumberFormat.CurrencyDecimalSeparator = ','; 


Yes, I am sure , changes are not seen by the
 ci.NumberFormat.CurrencyDecimalSeparator
in windows 7. but in xp, no problem. So I thought, if I assign that value, don't have to think if system use default value or value that user assign manually later.



View PosttlhIn`toq, on 21 May 2011 - 04:55 AM, said:

You haven't really described the problem. What is your end goal, not the path you are trying to take to get there?

Trying to 'reach' the control panel is basically pointless if you think you are going to read the information in it. It doesn't contain information all the time. It reads the current System.Globaliation values when it launches, it allows you to change those values, then it evaporates when you close the control panel.

Are you trying to make sure you use the right currency separator, even if the user changes it after you launched your application? If that is the case use a property instead of a field.

string decimalSeparator
{
     get { return ci.NumberFormat.CurrencyDecimalSeparator;
}



If you're just trying to format/display currency correctly, don't do the formatting yourself: let the OS do that for you. That's what the string.format method is for.
c Currency {0:c} $1.42 -$12,400

This is probably the de factor resource for using String.Format()
http://blog.stevex.n...ting-in-csharp/

Was This Post Helpful? 0
  • +
  • -

#4 dnur   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-May 11

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

Posted 21 May 2011 - 05:18 AM

or just reach and use decimalSeparator. But For example I change it with . (dot) from control panel, but when I call with
ci.NumberFormat.CurrencyDecimalSeparator

in code, still return to me the default value , (comma).
what should I do?

View PosttlhIn`toq, on 21 May 2011 - 04:55 AM, said:

You haven't really described the problem. What is your end goal, not the path you are trying to take to get there?

Trying to 'reach' the control panel is basically pointless if you think you are going to read the information in it. It doesn't contain information all the time. It reads the current System.Globaliation values when it launches, it allows you to change those values, then it evaporates when you close the control panel.

Are you trying to make sure you use the right currency separator, even if the user changes it after you launched your application? If that is the case use a property instead of a field.

string decimalSeparator
{
     get { return ci.NumberFormat.CurrencyDecimalSeparator;
}



If you're just trying to format/display currency correctly, don't do the formatting yourself: let the OS do that for you. That's what the string.format method is for.
c Currency {0:c} $1.42 -$12,400

This is probably the de factor resource for using String.Format()
http://blog.stevex.n...ting-in-csharp/

Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6259
  • View blog
  • Posts: 24,028
  • Joined: 23-August 08

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

Posted 21 May 2011 - 06:31 AM

Check out the registry hive HKEY_CURRENT_USER\Control Panel\International
Was This Post Helpful? 1
  • +
  • -

#6 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6536
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

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

Posted 21 May 2011 - 06:47 AM

Because you are getting Cultural Information specific to the culture currently set. In other words, what is the default separator for the current culture. For the culture ENG the separator is a comma.

I do see where you problem is coming from though. If someone has for some weird reason changed the value in the control panel that isn't seen in the Cultural Info. And you're trying to retreive that custom separator.

I didn't think it would be a big deal until I tried it. I set the separator to the ] symbol just to make it obvious. Then tried to retrieve it from the cultural info.

Attached Image

Attached Image

As you can see, the string.format is able to retrieve it for the currency format. But otherwise you get what is defined in the default for that culture.

JackOfAllTrades pointed out that you could find it by going through the supplied registry.

I went a different route and avoided the registry (safer for beginners) and created a test currency string then interrogated it for my specific needs. Its only 4 lines, registry safe, doesn't require registry permissions and should still work with most cultures.

            string tester = string.Format("{0:c}", 1234.56);// In Eng this would be $1,234.56
            string symbol = tester.ToCharArray()[0].ToString();  // In eng this would be $
            string thousands = tester.ToCharArray()[2].ToString();  // In eng this would be comma ,
            string coins = tester.ToCharArray()[6].ToString();  // In eng this would be period .


Was This Post Helpful? 1
  • +
  • -

#7 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6536
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

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

Posted 21 May 2011 - 06:58 AM

Also: I just have to ask... What is the custom change being made? Usually people don't need to change the decimal separator for their country. It's better to change the country to match the need.

Or if you are making an accounting program and you need to produce reports for different countries then load/use that countries culture info.

You can be using a Mexico-Spanish culture and still retreive the US English information for a report, for example.

NumberFormatInfo nfi = new CultureInfo("en-US", false).NumberFormat; //English USA
NumberFormatInfo nfi = new CultureInfo("es-MX", false).NumberFormat; // Spanish Mexico


You shouldn't be modifying the culture of the OS to format your reports/display. You should be doing anything custom within your application and leave the OS the way it is supposed to be. Otherwise you risk screwing up other program running on the computer. Yours is not the only application that might need that cultural information.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1