本文整理汇总了C#中System.Drawing.Graphics.TextRenderingHint属性的典型用法代码示例。如果您正苦于以下问题:C# Graphics.TextRenderingHint属性的具体用法?C# Graphics.TextRenderingHint怎么用?C# Graphics.TextRenderingHint使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Drawing.Graphics
的用法示例。
在下文中一共展示了Graphics.TextRenderingHint属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChangeTextRenderingHintAndTextContrast
private void ChangeTextRenderingHintAndTextContrast(PaintEventArgs e)
{
// Retrieve the graphics object.
Graphics formGraphics = e.Graphics;
// Declare a new font.
Font myFont = new Font(FontFamily.GenericSansSerif, 20,
FontStyle.Regular);
// Set the TextRenderingHint property.
formGraphics.TextRenderingHint =
System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
// Draw the string.
formGraphics.DrawString("Hello World", myFont,
Brushes.Firebrick, 20.0F, 20.0F);
// Change the TextRenderingHint property.
formGraphics.TextRenderingHint =
System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
// Draw the string again.
formGraphics.DrawString("Hello World", myFont,
Brushes.Firebrick, 20.0F, 60.0F);
// Set the text contrast to a high-contrast setting.
formGraphics.TextContrast = 0;
// Draw the string.
formGraphics.DrawString("Hello World", myFont,
Brushes.DodgerBlue, 20.0F, 100.0F);
// Set the text contrast to a low-contrast setting.
formGraphics.TextContrast = 12;
// Draw the string again.
formGraphics.DrawString("Hello World", myFont,
Brushes.DodgerBlue, 20.0F, 140.0F);
// Dispose of the font object.
myFont.Dispose();
}
示例2: SmoothingFonts
/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald
Publisher: Apress
ISBN: 1590590457
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing.Text;
namespace GDI_Basics
{
/// <summary>
/// Summary description for SmoothingFonts.
/// </summary>
public class SmoothingFonts : System.Windows.Forms.Form
{
internal System.Windows.Forms.Label Label3;
internal System.Windows.Forms.Label Label2;
internal System.Windows.Forms.Label Label1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public SmoothingFonts()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Label3 = new System.Windows.Forms.Label();
this.Label2 = new System.Windows.Forms.Label();
this.Label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// Label3
//
this.Label3.BackColor = System.Drawing.Color.White;
this.Label3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.Label3.Location = new System.Drawing.Point(272, 168);
this.Label3.Name = "Label3";
this.Label3.Size = new System.Drawing.Size(128, 16);
this.Label3.TabIndex = 5;
this.Label3.Text = " ClearTypeGridFit";
//
// Label2
//
this.Label2.BackColor = System.Drawing.Color.White;
this.Label2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.Label2.Location = new System.Drawing.Point(272, 100);
this.Label2.Name = "Label2";
this.Label2.Size = new System.Drawing.Size(128, 16);
this.Label2.TabIndex = 4;
this.Label2.Text = " AntiAliasGridFit";
//
// Label1
//
this.Label1.BackColor = System.Drawing.Color.White;
this.Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.Label1.Location = new System.Drawing.Point(272, 36);
this.Label1.Name = "Label1";
this.Label1.Size = new System.Drawing.Size(128, 16);
this.Label1.TabIndex = 3;
this.Label1.Text = " SingleBitPerPixelGridFit";
//
// SmoothingFonts
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
this.ClientSize = new System.Drawing.Size(440, 314);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.Label3,
this.Label2,
this.Label1});
this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.Name = "SmoothingFonts";
this.Text = "SmoothingFonts";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.SmoothingFonts_Paint);
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new SmoothingFonts());
}
private void SmoothingFonts_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Font TextFont = new Font("Times New Roman", 25, FontStyle.Italic);
e.Graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;
e.Graphics.DrawString("Sample Text", TextFont, Brushes.Black, 20, 20);
e.Graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
e.Graphics.DrawString("Sample Text", TextFont, Brushes.Black, 20, 85);
e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
e.Graphics.DrawString("Sample Text", TextFont, Brushes.Black, 20, 150);
}
}
}