提供用于测量和呈现文本的方法。 此类不能被继承。
命名空间: System.Windows.Forms
程序集: System.Windows.Forms(位于 System.Windows.Forms.dll)
System.Object
System.Windows.Forms.TextRenderer
语法:
public sealed class TextRenderer
TextRenderer 类提供了一套 static 可用于测量和在 Windows 窗体控件上绘制文本的方法。
您可以操作如何通过使用一种绘制文本 DrawText 采用重载 TextFormatFlags 参数。 例如,默认行为 TextRenderer 是将填充添加到所绘制文本以容纳延伸的标志符号的边框。 如果您需要绘制文本行,如果没有这些额外的空格则应使用的版本 DrawText 和 MeasureText 采用 Size 和 TextFormatFlags 参数。 有关示例,请参见MeasureText(IDeviceContext,String,Font,Size,TextFormatFlags)。
说明 |
---|
TextRenderer 的 DrawText 方法不支持打印。 您应该始终使用 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
转载于:https://blog.51cto.com/jiaojusuimu/1881265