Uredi

Deli z drugimi prek


StringFormat.SetDigitSubstitution(Int32, StringDigitSubstitute) Method

Definition

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

public:
 void SetDigitSubstitution(int language, System::Drawing::StringDigitSubstitute substitute);
public void SetDigitSubstitution (int language, System.Drawing.StringDigitSubstitute substitute);
member this.SetDigitSubstitution : int * System.Drawing.StringDigitSubstitute -> unit
Public Sub SetDigitSubstitution (language As Integer, substitute As StringDigitSubstitute)

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.

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 );
   }
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);
}
Public Sub SetDigitSubExample(ByVal e As PaintEventArgs)
    Dim g As Graphics = e.Graphics
    Dim blueBrush As New SolidBrush(Color.FromArgb(255, 0, 0, 255))
    Dim myFont As New Font("Courier New", 12)
    Dim myStringFormat As New StringFormat
    Dim myString As String = "0 1 2 3 4 5 6 7 8 9"

    ' Arabic (0x0C01) digits.

    ' Use National substitution method.
    myStringFormat.SetDigitSubstitution(&HC01, _
    StringDigitSubstitute.National)
    g.DrawString("Arabic:" & ControlChars.Cr & _
    "Method of substitution = National:     " & myString, _
    myFont, blueBrush, New PointF(10.0F, 20.0F), myStringFormat)

    ' Use Traditional substitution method.
    myStringFormat.SetDigitSubstitution(&HC01, _
    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(&H41E, _
    StringDigitSubstitute.National)
    g.DrawString("Thai:" & ControlChars.Cr & _
    "Method of substitution = National:     " & myString, _
    myFont, blueBrush, New PointF(10.0F, 85.0F), myStringFormat)

    ' Use Traditional substitution method.
    myStringFormat.SetDigitSubstitution(&H41E, _
    StringDigitSubstitute.Traditional)
    g.DrawString("Method of substitution = Traditional:  " _
    & myString, myFont, blueBrush, New PointF(10.0F, 120.0F), _
    myStringFormat)
End Sub

Applies to