StringFormat.SetDigitSubstitution(Int32, StringDigitSubstitute) 方法

定义

指定在将本地数字替换为西部数字时要使用的语言和方法。

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)

参数

language
Int32

国家语言支持(NLS)语言标识符,用于标识本地数字替换为西部数字时将使用的语言。 可以将 CultureInfo 对象的 LCID 属性作为 NLS 语言标识符传递。 例如,假设通过将字符串“ar-EG”传递给 CultureInfo 构造函数来创建 CultureInfo 对象。 如果将该 CultureInfo 对象的 LCID 属性以及 Traditional 传递给 SetDigitSubstitution(Int32, StringDigitSubstitute) 方法,则在显示时将替换 Arabic-Indic 位数。

substitute
StringDigitSubstitute

StringDigitSubstitute 枚举的元素,用于指定数字的显示方式。

示例

下面的示例设计用于 Windows 窗体,它需要 PaintEventArgse,这是 Paint 事件处理程序的参数。 该代码执行以下操作:

  • StringFormat设置要使用的语言和要使用的替换方法。

  • 绘制字符串。

  • 对两种不同的语言(阿拉伯语和泰文)重复上述两个步骤。

国家替代方法和传统替换方法针对这两种语言的每一种语言都进行了演示。 国家/地区方法根据用户区域设置的官方国家语言显示数字。 传统方法根据用户的本机脚本或语言显示数字,这可能不同于官方国家语言。

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

适用于