【发布时间】:2018-01-16 15:50:38
【问题描述】:
我使用了这个答案:Alpha in ForeColor 创建一个自定义标签元素,允许在 ARGB 中淡出,这与默认标签不同。
using System;
using System.Drawing;
using System.Windows.Forms;
public class MyLabel : Label {
protected override void OnPaint(PaintEventArgs e) {
Rectangle rc = this.ClientRectangle;
StringFormat fmt = new StringFormat(StringFormat.GenericTypographic);
using (var br = new SolidBrush(this.ForeColor)) {
e.Graphics.DrawString(this.Text, this.Font, br, rc, fmt);
}
}
}
我很好奇如何在这个类中实现 TextAlign 以使文本内容正确对齐。
【问题讨论】:
-
为此设置“StringFormat”中的属性:msdn.microsoft.com/en-us/library/…
标签: c# winforms label text-alignment