Kin*_*ing 26
我认为你必须自定义绘制自己的控件.这是一个例子Label.请注意,这只是一个演示,您应该尝试在winforms中查找有关自定义绘画的更多信息:
public class CustomLabel : Label
{
public CustomLabel()
{
OutlineForeColor = Color.Green;
OutlineWidth = 2;
}
public Color OutlineForeColor { get; set; }
public float OutlineWidth { get; set; }
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.FillRectangle(new SolidBrush(BackColor), ClientRectangle);
using (GraphicsPath gp = new GraphicsPath())
using (Pen outline = new Pen(OutlineForeColor, OutlineWidth)
{ LineJoin = LineJoin.Round})
using(StringFormat sf = new StringFormat())
using(Brush foreBrush = new SolidBrush(ForeColor))
{
gp.AddString(Text, Font.FontFamily, (int)Font.Style,
Font.Size, ClientRectangle, sf);
e.Graphics.ScaleTransform(1.3f, 1.35f);
e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
e.Graphics.DrawPath(outline, gp);
e.Graphics.FillPath(foreBrush, gp);
}
}
}
Run Code Online (Sandbox Code Playgroud)
您可以通过OutlineForeColor属性更改轮廓颜色,您可以通过属性更改轮廓宽度OutlineWidth.当您在设计器中更改这些属性时,效果不会立即应用(因为没有任何代码可以执行此操作,我希望保持简洁和简单),仅在窗体聚焦时才应用效果.
你可以添加更多的是映射TextAlign到Alignment的StringFormat(命名sf代码),你也可以覆盖一些事件提出的方法在外观和感觉(如改变添加更多的控制ForeColor,当鼠标移动到标签. ..).你甚至可以创建一些阴影效果和发光效果(它需要更多的代码).

| 归档时间: |
|
| 查看次数: |
8921 次 |
| 最近记录: |