I have a C# form application that needs to override the DigitShapes (Use Native Digits) setting. What I need to achieve is to always display digits using their original shapes. So I need to always run with the DigitShapes set to "None", regardless of the Use Native Digits setting in the "Region and Language" setting in Windows. (I am testing in Windows 7).
For example, if the character value is between 0x30 and 0x39 I need to display the numeric using the western Arabic numerals "123" etc. (http://en.wikipedia.org/wiki/Arabic_numerals) If the character value is between 0x660 and 0x669, I want it to display with the Indic glyph (http://en.wikipedia.org/wiki/Eastern_Arabic_numerals)
In the windows "Region and Language" dialog, when "Use Native Digits" is set to "Never", then the application numerics always displays as desired. When "Use Native Digits" is set to "Context", then values in the 0x30 to 0x39 will display with the Indic glyph when the direction is right to left (RTL) or if it is preceded by a BiDi character with a RTL directionality. My understanding is that the DigitShapes setting maps to the "Use Native Digits" setting in the "Region and Language" dialog.
By default, the arabic locales default "Use Native Digits" to "Context". I want to force my application to always run as if the setting is "Never".
I have been attempting to override the locale setting in my application to force DigitShapes to be "none". The sample code below gets the current locale context and overrides the DigitShapes and then resets the culture for the application. In the debugger I can see that if I query the thread culture, it does indeed have DigitShapes set to "None". However, numerics are still being substituted during display in a RTL environment.
I have tried calling ClearCachedData, but that doesn't seem to help. Is this a bug or am I missing a step to force my application to never substitute digits?
Sample code
static void Main(string []args)
{
System.Globalization.CultureInfo cinfo = (System.Globalization.CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
Thread.CurrentThread.CurrentCulture.ClearCachedData();
Application.CurrentCulture.ClearCachedData();
cinfo.NumberFormat.DigitSubstitution = System.Globalization.DigitShapes.None;
Thread.CurrentThread.CurrentCulture = cinfo;
Thread.CurrentThread.CurrentUICulture = cinfo;
Application.CurrentCulture = cinfo;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MyForm(args));
}
Help is appreciated.
Robert