本文整理汇总了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);
}
}