C#如何制作背景颜色未100%填充的标签

问题描述

让我向您展示我想要得到的示例:

Label with backcolor not 100%

有些标签是 "normal" ,其他标签未 100% 填充。 为了实现这一点,标签控件可能不是开始时最好的项目,但我想不出更好的项目。有好心人吗?

解决方法

您必须先使用油漆来创建自定义标签

class HalfColorLabel:Label
{
        protected override void OnPaint(PaintEventArgs e)
        {
            SolidBrush brush = new SolidBrush(Color.Orange);
            Graphics g = e.Graphics;
            g.FillRectangle(brush,new Rectangle(0,this.Width,this.Height/2));
            base.OnPaint(e);
        }
}

重新构建解决方案

enter image description here

选择半色标签

enter image description here