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 Form 應用程式建立第一個視窗之前呼叫這個方法。

範例

重要

若要在 Visual Basic 2005 或更新版本中設定 的 UseCompatibleTextRendering 預設值,請參閱 WindowsFormsApplicationBase.UseCompatibleTextRendering

針對 C# 應用程式,Visual Studio 會自動在Program.cs檔案中新增對 的呼叫 SetCompatibleTextRenderingDefault 。 若要變更文字轉譯預設值,請修改產生的程式碼。

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 圖形庫為基礎的 類別,或 Graphics 以 GDI+ 圖形庫為基礎的 類別來轉譯其文字 TextRenderer 。 由於 GDI+ 的效能和當地語系化問題,.NET Framework 2.0 中進行了這項變更。 使用 SetCompatibleTextRenderingDefault 來為支援該屬性的控制項設定 屬性的 UseCompatibleTextRendering 預設值。

屬性 UseCompatibleTextRendering 旨在提供Windows Forms控制項之間的視覺相容性,這些控制項會使用 TextRenderer 類別轉譯文字,以及使用 Graphics 類別執行自訂文字轉譯的應用程式。 在大部分情況下,如果您的應用程式未從 .NET Framework 1.0 或 .NET Framework 1.1 升級,建議您將 UseCompatibleTextRendering 設定為 的 false 預設值。

GDI 型 TextRenderer 類別是在 .NET Framework 2.0 中引進,以改善效能、讓文字看起來更好,以及改善國際字型的支援。 在舊版的 .NET Framework 中,GDI+ 型 Graphics 類別是用來執行所有文字轉譯。 GDI 會計算與 GDI+ 不同的字元間距和自動換行。 在使用 Graphics 類別來呈現文字的 Windows Forms 應用程式中,這可能會造成控制項的文字,而該 TextRenderer 控制項的文字會與應用程式中的其他文字不同。 若要解決這個不相容問題,您可以將 屬性設定 UseCompatibleTextRenderingtrue 。 若要針對應用程式中所有支援的控制項設定 UseCompatibleTextRenderingtrue ,請使用 的 true 引數呼叫 SetCompatibleTextRenderingDefault 方法。

如果您的Windows Forms程式碼裝載在另一個應用程式中,例如 Internet Explorer,您就不應該呼叫此方法。 只在獨立Windows Forms應用程式中呼叫這個方法。

適用於

另請參閱