أعتقد أنه يجب عليك رسم جهاز التحكم الخاص بك المخصص. هنا مثال على أ 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
عندما يكون الماوس فوق الملصق ...). يمكنك حتى إنشاء بعض تأثير الظل وتأثير التوهج (يتطلب المزيد من التعليمات البرمجية).