提供用于测量和呈现文本的方法。 此类不能被继承。

命名空间:                   System.Windows.Forms
程序集:         System.Windows.Forms(位于 System.Windows.Forms.dll)

继承层次结构

System.Object
System.Windows.Forms.TextRenderer

语法:

public sealed class TextRenderer

方法


名称说明
System_CAPS_pubmethodSystem_CAPS_staticDrawText(IDeviceContext,String,Font,Point,Color)

使用指定的设备上下文、 字体和颜色的指定位置绘制指定的文本。

System_CAPS_pubmethodSystem_CAPS_staticDrawText(IDeviceContext,String,Font,Point,Color,Color)

在指定的位置,并使用指定的设备上下文、 字体、 颜色和背景色绘制指定的文本。

System_CAPS_pubmethodSystem_CAPS_staticDrawText(IDeviceContext,String,Font,Point,Color,Color,TextFormatFlags)

使用指定的设备上下文、 字体、 颜色、 背景色的指定位置绘制指定的文本和格式说明

System_CAPS_pubmethodSystem_CAPS_staticDrawText(IDeviceContext,String,Font,Point,Color,TextFormatFlags)

在使用指定的设备上下文、 字体、 颜色和格式设置的说明指定的位置绘制指定的文本。

System_CAPS_pubmethodSystem_CAPS_staticDrawText(IDeviceContext,String,Font,Rectangle,Color)

绘制的指定边界内,使用指定的设备上下文、 字体和颜色的指定的文本。

System_CAPS_pubmethodSystem_CAPS_staticDrawText(IDeviceContext,String,Font,Rectangle,Color,Color)

绘制指定使用指定的设备上下文、 字体、 颜色和背景色的边界内的指定的文本。

System_CAPS_pubmethodSystem_CAPS_staticDrawText(IDeviceContext,String,Font,Rectangle,Color,Color,TextFormatFlags)

绘制指定使用指定的设备上下文、 字体、 颜色、 背景色的边界内的指定的文本和格式说明。

System_CAPS_pubmethodSystem_CAPS_staticDrawText(IDeviceContext,String,Font,Rectangle,Color,TextFormatFlags)

绘制指定的文本,使用指定的设备上下文、 字体、 颜色和格式设置的说明指定的边界内。

System_CAPS_pubmethodEquals(Object)

确定指定的对象是否等于当前对象。(继承自 Object。)

System_CAPS_pubmethodGetHashCode()

作为默认哈希函数。(继承自 Object。)

System_CAPS_pubmethodGetType()

获取当前实例的 Type(继承自 Object。)

System_CAPS_pubmethodSystem_CAPS_staticMeasureText(IDeviceContext,String,Font)

提供的尺寸,以像素为单位指定使用指定的设备上下文中指定的字体绘制的文本。

System_CAPS_pubmethodSystem_CAPS_staticMeasureText(IDeviceContext,String,Font,Size)

提供的尺寸,以像素为单位指定的文本时使用指定的字体在指定的设备上下文中,使用指定的大小创建的初始文本边框绘制。

System_CAPS_pubmethodSystem_CAPS_staticMeasureText(IDeviceContext,String,Font,Size,TextFormatFlags)

提供的尺寸,以像素为单位指定的文本绘制并用指定的设备上下文、 字体和格式设置的说明,使用指定的大小来创建初始的边框的文本。

System_CAPS_pubmethodSystem_CAPS_staticMeasureText(String,Font)

提供的尺寸,以像素为单位指定的文本时使用指定的字体绘制。

System_CAPS_pubmethodSystem_CAPS_staticMeasureText(String,Font,Size)

提供的尺寸,以像素为单位指定的文本时使用指定的字体,使用指定的大小创建初始边框绘制。

System_CAPS_pubmethodSystem_CAPS_staticMeasureText(String,Font,Size,TextFormatFlags)

提供的尺寸,以像素为单位指定的文本绘制并用指定的字体和格式设置的说明,使用指定的大小来创建初始的边框的文本。

System_CAPS_pubmethodToString()

返回表示当前对象的字符串。(继承自 Object。)

备注

 TextRenderer 类提供了一套 static 可用于测量和在 Windows 窗体控件上绘制文本的方法。

您可以操作如何通过使用一种绘制文本 DrawText 采用重载 TextFormatFlags 参数。 例如,默认行为 TextRenderer 是将填充添加到所绘制文本以容纳延伸的标志符号的边框。 如果您需要绘制文本行,如果没有这些额外的空格则应使用的版本 DrawTextMeasureText 采用 SizeTextFormatFlags 参数。 有关示例,请参见MeasureText(IDeviceContext,String,Font,Size,TextFormatFlags)

System_CAPS_note说明

 TextRendererDrawText 方法不支持打印。 您应该始终使用 DrawString 方法 Graphics 类。

示例

下面的代码示例演示如何使用 DrawText 方法。 若要运行本示例,请将代码粘贴到一个 Windows 窗体并调用 RenderText1 从窗体的 Paint 事件处理程序,并传递 e 作为 PaintEventArgs


private void RenderText1(PaintEventArgs e)
{
    TextRenderer.DrawText(e.Graphics, "Regular Text", this.Font, 
        new Point(10, 10), SystemColors.ControlText);

}

备注:转自https://msdn.microsoft.com/zh-cn/library/system.windows.forms.textrenderer(v=vs.110).aspx