本文整理匯總了C#中System.Drawing.StringFormat.Alignment屬性的典型用法代碼示例。如果您正苦於以下問題:C# StringFormat.Alignment屬性的具體用法?C# StringFormat.Alignment怎麽用?C# StringFormat.Alignment使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.Drawing.StringFormat
的用法示例。
在下文中一共展示了StringFormat.Alignment屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ShowLineAndAlignment
private void ShowLineAndAlignment(PaintEventArgs e)
{
// Construct a new Rectangle .
Rectangle displayRectangle =
new Rectangle (new Point(40, 40), new Size (80, 80));
// Construct 2 new StringFormat objects
StringFormat format1 = new StringFormat(StringFormatFlags.NoClip);
StringFormat format2 = new StringFormat(format1);
// Set the LineAlignment and Alignment properties for
// both StringFormat objects to different values.
format1.LineAlignment = StringAlignment.Near;
format1.Alignment = StringAlignment.Center;
format2.LineAlignment = StringAlignment.Center;
format2.Alignment = StringAlignment.Far;
// Draw the bounding rectangle and a string for each
// StringFormat object.
e.Graphics.DrawRectangle(Pens.Black, displayRectangle);
e.Graphics.DrawString("Showing Format1", this.Font,
Brushes.Red, (RectangleF)displayRectangle, format1);
e.Graphics.DrawString("Showing Format2", this.Font,
Brushes.Red, (RectangleF)displayRectangle, format2);
}
示例2: Main
//引入命名空間
using System;
using System.Drawing;
using System.Windows.Forms;
class HelloCenteredRectangle: Form
{
public static void Main()
{
Application.Run(new HelloCenteredRectangle());
}
public HelloCenteredRectangle()
{
BackColor = SystemColors.Window;
ForeColor = SystemColors.WindowText;
ResizeRedraw = true;
}
protected override void OnPaint(PaintEventArgs pea)
{
Graphics grfx = pea.Graphics;
StringFormat strfmt = new StringFormat();
strfmt.Alignment = StringAlignment.Center;
strfmt.LineAlignment = StringAlignment.Center;
grfx.DrawString("Hello, world!", Font, new SolidBrush(ForeColor),
ClientRectangle, strfmt);
}
}