Application.SetCompatibleTextRenderingDefault(Boolean) 方法

定義

設定某些控制項上定義屬性 UseCompatibleTextRendering 的全應用程式預設值。

public:
 static void SetCompatibleTextRenderingDefault(bool defaultValue);
public static void SetCompatibleTextRenderingDefault(bool defaultValue);
static member SetCompatibleTextRenderingDefault : bool -> unit
Public Shared Sub SetCompatibleTextRenderingDefault (defaultValue As Boolean)

參數

defaultValue
Boolean

這是新控制項的預設值。 若 true,支援 UseCompatibleTextRendering 的新控制項使用 GDI+ 基礎 Graphics 的文字渲染類別;若 false,則新控制項使用 GDI 基礎 TextRenderer 類別。

例外狀況

你只能在 Windows Forms 應用程式建立第一個視窗之前呼叫此方法。

範例

Important

若要設定 2005 Visual Basic 或之後 UseCompatibleTextRendering 的預設值,請參見 WindowsFormsApplicationBase.UseCompatibleTextRendering

對於 C# 應用程式,Visual Studio 會自動在 Program.cs 檔案中自動新增對 的呼叫。 要更改文字渲染預設,請修改產生的程式碼。

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }
}

備註

某些Windows Forms控制項可以使用基於 GDI 圖形庫的 TextRenderer 類別,或基於 GDI+ 圖形庫的 Graphics 類別來渲染文字。 此變更是在 .NET Framework 2.0 中進行的,原因是 GDI+ 的效能與在地化問題。 用 SetCompatibleTextRenderingDefault 來設定支援該屬性的控制項的預設值 UseCompatibleTextRendering

UseCompatibleTextRendering 屬性旨在提供使用 TextRenderer 類別渲染文字的 Windows Forms 控制項與使用 Graphics 類別進行自訂文字渲染的應用程式之間的視覺相容性。 在大多數情況下,建議將 UseCompatibleTextRendering 設定為預設值 false

基於 GDI 的 TextRenderer 類別於 .NET Framework 2.0 中引入,目的是提升效能、讓文字看起來更美觀,並提升對國際字型的支援。 在早期版本的 .NET 框架中,所有文字渲染皆使用基於 GDI+ 的 Graphics 類別。 GDI 計算字元間距與字元換行的方式與 GDI+ 不同。 在使用 Graphics 類別來渲染文字的Windows Forms應用程式中,這可能導致使用 TextRenderer 的控制項中的文字顯示與應用程式中其他文字不同。 為了解決這種不相容性問題,你可以將屬性設 UseCompatibleTextRenderingtrue。 若要將 對應用程式中所有支援的控制項設UseCompatibleTextRendering為 ,true請以參數true呼叫SetCompatibleTextRenderingDefault方法 。

如果你的 Windows Forms 程式碼託管在其他應用程式(如 Internet Explorer)中,絕不應該呼叫此方法。 此方法僅在獨立的 Windows Forms 應用程式中呼叫。

適用於

另請參閱