1. 程式人生 > >Application.SetCompatibleTextRenderingDefault的作用及使用方法 分類: Win Forms 2006-04-23 12:23 7291人閱讀 評論(7) 收

Application.SetCompatibleTextRenderingDefault的作用及使用方法 分類: Win Forms 2006-04-23 12:23 7291人閱讀 評論(7) 收

    在.net2.0中增加了很多新的內容,比如:Application.SetCompatibleTextRenderingDefault方法。
但是,在VS2005附帶的MSDN2005中卻沒有它的詳細說明。為此,我查找了MSDN官方網站和MSDN2005的相關屬性,獲悉了該方法的部分資訊。現將其記錄如下。

一、相關連結

1.MSDN網站有Application.SetCompatibleTextRenderingDefault的詳細說明,地址:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.application.setcompatibletextrenderingdefault(VS.80).aspx


2.MSDN2005的相關屬性UseCompatibleTextRendering,地址:ms-help://MS.MSDNQTR.v80.chs/MS.MSDN.v80/MS.NETDEVFX.v20.chs/CPref17/html/P_System_Windows_Forms_ButtonBase_UseCompatibleTextRendering.htm

二、總結

1.作用:在應用程式範圍內設定控制元件顯示文字的預設方式(可以設為使用新的GDI+ , 還是舊的GDI)
true使用GDI+方式顯示文字,
false使用GDI方式顯示文字.
2.只能在單獨執行窗體的程式中呼叫該方法;不能在外掛式的程式中呼叫該方法.
3.只能在程式建立任何窗體前呼叫該方法,否則會引發InvalidOperationException異常.

三、MSDN網站對Application.SetCompatibleTextRenderingDefault方法的說明

.NET Framework Class Library   Application.SetCompatibleTextRenderingDefault Method  

Note: This method is new in the .NET Framework version 2.0.

Sets the application-wide default for the UseCompatibleTextRendering property defined on certain controls.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax
Visual Basic (Declaration)
Public Shared Sub SetCompatibleTextRenderingDefault ( _
    defaultValue As Boolean _
)
Visual Basic (Usage)
Dim defaultValue As Boolean Application.SetCompatibleTextRenderingDefault(defaultValue)
public static void SetCompatibleTextRenderingDefault (
    bool defaultValue
)
public:
static void SetCompatibleTextRenderingDefault (
    bool defaultValue
)
public static void SetCompatibleTextRenderingDefault (
    boolean defaultValue
)
public static function SetCompatibleTextRenderingDefault (
    defaultValue : boolean
)

Parameters

defaultValue

The default value to use for new controls. If true, new controls that supportUseCompatibleTextRendering use GDI+ for text rendering; if false, new controls use GDI+.

Exceptions
Exception type Condition

You can only call this method before the first window is created by your Windows Forms application.

Remarks

Certain Windows Forms controls can render their text using either the GDI graphics library, or the newer GDI+ library. This change was made because of performance and localization issues with GDI+. By default, existing controls that support the UseCompatibleTextRendering property are set to true for backwards compatibility, but all new controls in environments such as Visual Studio have this property set to false. UseSetCompatibleTextRenderingDefault when you wish to switch the default text rendering for new controls.

You should never call this method if your Windows Forms code is hosted in another application, such as Internet Explorer. Only call this method in stand-alone Windows Forms applications.

this page Platforms

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, seeSystem Requirements.

Version Information

.NET Framework

Supported in: 2.0