StringFormat::SetDigitSubstitution Method (Int32, StringDigitSubstitute)

 

Specifies the language and method to be used when local digits are substituted for western digits.

Namespace:   System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)

public:
void SetDigitSubstitution(
	int language,
	StringDigitSubstitute substitute
)

Parameters

language
Type: System::Int32

A National Language Support (NLS) language identifier that identifies the language that will be used when local digits are substituted for western digits. You can pass the LCID property of a CultureInfo object as the NLS language identifier. For example, suppose you create a CultureInfo object by passing the string "ar-EG" to a CultureInfo constructor. If you pass the LCID property of that CultureInfo object along with Traditional to the SetDigitSubstitution method, then Arabic-Indic digits will be substituted for western digits at display time.

substitute
Type: System.Drawing::StringDigitSubstitute

An element of the StringDigitSubstitute enumeration that specifies how digits are displayed.

The following example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. The code performs the following actions:

  • Sets, for the StringFormat, the language to be used and the substitution method to be used.

  • Draws the string.

  • Repeats the above two steps for two different languages (Arabic and Thai).

The National substitution method and Traditional substitution method are demonstrated for each of the two languages. The National method displays digits according to the official national language of the user's locale. The Traditional method displays digits according to the user's native script or language, which may be different from the official national language.

public:
   void SetDigitSubExample( PaintEventArgs^ e )
   {
      Graphics^ g = e->Graphics;
      SolidBrush^ blueBrush = gcnew SolidBrush( Color::FromArgb( 255, 0, 0, 255 ) );
      System::Drawing::Font^ myFont = gcnew System::Drawing::Font( "Courier New",12 );
      StringFormat^ myStringFormat = gcnew StringFormat;
      String^ myString = "0 1 2 3 4 5 6 7 8 9";

      // Arabic (0x0C01) digits.
      // Use National substitution method.
      myStringFormat->SetDigitSubstitution( 0x0C01, StringDigitSubstitute::National );
      g->DrawString( String::Format( "Arabic:\nMethod of substitution = National:     {0}", myString ), myFont, blueBrush, PointF(10.0f,20.0f), myStringFormat );

      // Use Traditional substitution method.
      myStringFormat->SetDigitSubstitution( 0x0C01, StringDigitSubstitute::Traditional );
      g->DrawString( String::Format( "Method of substitution = Traditional:  {0}", myString ), myFont, blueBrush, PointF(10.0f,55.0f), myStringFormat );

      // Thai (0x041E) digits.
      // Use National substitution method.
      myStringFormat->SetDigitSubstitution( 0x041E, StringDigitSubstitute::National );
      g->DrawString( String::Format( "Thai:\nMethod of substitution = National:     {0}", myString ), myFont, blueBrush, PointF(10.0f,85.0f), myStringFormat );

      // Use Traditional substitution method.
      myStringFormat->SetDigitSubstitution( 0x041E, StringDigitSubstitute::Traditional );
      g->DrawString( String::Format( "Method of substitution = Traditional:  {0}", myString ), myFont, blueBrush, PointF(10.0f,120.0f), myStringFormat );
   }

.NET Framework
Available since 1.1
Return to top
Show: