나는 당신이 자신의 컨트롤을 맞춤 페인트해야한다고 생각합니다. 다음은 다음에 대한 예입니다 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);
}
}
}
개요 색상을 통해 개요를 변경할 수 있습니다 OutlineForeColor
속성, 당신은 개요 너비를 OutlineWidth
재산. 디자이너에서 이러한 속성을 변경하면 효과가 즉시 적용되지 않습니다 (이를 수행 할 코드가 없기 때문에 짧고 간단하게 유지하려면) 양식이 집중 될 때만 효과가 적용됩니다.
더 추가 할 수있는 것은 매핑입니다 TextAlign
~로 Alignment
의 StringFormat
(명명 된 sf
코드에서), 당신은 또한 외관과 느낌에 대한 더 많은 제어를 추가하기 위해 일부 이벤트 제기 방법을 무시할 수 있습니다 (예 : ForeColor
마우스가 레이블 위에있을 때 ...). 그림자 효과와 글로우 효과를 만들 수도 있습니다 (훨씬 더 많은 코드가 필요합니다).