Font.ToString Font.ToString Font.ToString Font.ToString Method


傳回這個 Font 的人們可解讀的字串表示。Returns a human-readable string representation of this Font.

 override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String


表示這個 Font 的字串。A string that represents this Font.


下列程式碼範例是針對與 Windows Forms 搭配使用所設計, 而且PaintEventArgs它需要e, 這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 建立 FontCreates a Font.

  • 取得表示字型的字串。Gets a string that represents the font.

  • 在訊息方塊中顯示字串。Displays the string in a message box.

   void ToString_Example( PaintEventArgs^ /*e*/ )
      // Create a Font object.
      System::Drawing::Font^ myFont = gcnew System::Drawing::Font( "Arial",16 );

      // Get a string that represents myFont.
      String^ fontString = myFont->ToString();

      // Display a message box with fontString.
      MessageBox::Show( fontString );
public void ToString_Example(PaintEventArgs e)
    // Create a Font object.
    Font myFont = new Font("Arial", 16);
    // Get a string that represents myFont.
    string fontString = myFont.ToString();
    // Display a message box with fontString.
Public Sub ToString_Example(ByVal e As PaintEventArgs)

    ' Create a Font object.
    Dim myFont As New Font("Arial", 16)

    ' Get a string that represents myFont.
    Dim fontString As String = myFont.ToString()

    ' Display a message box with fontString.
End Sub


傳回的字串具有下列格式:The returned string has the following format:

字體名稱 =fontName, 大小 =大小, 單位 =單位, GDiCharSet =GDiCharSet, GdiVerticalFont =布林值][Font: Name=fontName, Size=size, Units=units, GDiCharSet=gdiCharSet, GdiVerticalFont=boolean]