StringFormat.SetDigitSubstitution(Int32, StringDigitSubstitute) Method

Definition

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

C#
public void SetDigitSubstitution(int language, System.Drawing.StringDigitSubstitute substitute);

Parameters

language
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(Int32, StringDigitSubstitute) method, then Arabic-Indic digits will be substituted for western digits at display time.

substitute
StringDigitSubstitute

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

Examples

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.

C#
public void SetDigitSubExample(PaintEventArgs e)
{
    Graphics     g = e.Graphics;
    SolidBrush   blueBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255));
    Font         myFont = new Font("Courier New", 12);
    StringFormat myStringFormat = new 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(
        "Arabic:\nMethod of substitution = National:     " + myString,
        myFont, blueBrush, new PointF(10.0f, 20.0f), myStringFormat);
             
    // Use Traditional substitution method.
    myStringFormat.SetDigitSubstitution(0x0C01,
        StringDigitSubstitute.Traditional);
    g.DrawString(
        "Method of substitution = Traditional:  " + myString,
        myFont, blueBrush, new PointF(10.0f, 55.0f), myStringFormat);
             
    // Thai (0x041E) digits.
   
    // Use National substitution method.
    myStringFormat.SetDigitSubstitution(0x041E,
        StringDigitSubstitute.National);
    g.DrawString(
        "Thai:\nMethod of substitution = National:     " + myString,
        myFont, blueBrush, new PointF(10.0f, 85.0f), myStringFormat);
             
    // Use Traditional substitution method.
    myStringFormat.SetDigitSubstitution(0x041E,
        StringDigitSubstitute.Traditional);
    g.DrawString(
        "Method of substitution = Traditional:  " + myString,
        myFont, blueBrush, new PointF(10.0f, 120.0f), myStringFormat);
}

Applies to

Tuote Versiot
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10