如何生成中途褪色的文本?

How can I produce half-way faded text?

这个任务是一个简单的概念,只是不确定一个简单的方法来完成我的要求。


目标

让文本框、标签、自定义用户控件或其他类型的控件显示多行文本并将其淡出一半(如下图所示)。我希望它是透明的(如图所示)并且当然是可编辑的。我在想像自定义 UserControl : label 或类似的东西。也许覆盖标签的 OnPaint 并绘制表单内容(控件后面的所有内容)以模拟透明度。然后绘制文本,但可能会以某种方式对其应用某种类型的渐变滤镜?老实说,我不知道我会怎么做,但希望别人能做到。

谢谢!

我找到了一个解决方案,它看起来很完美,我需要花更多时间在它上面,稍后添加对文本对齐等的支持。但现在我最终想出了这个...

Note: Create a new User Control and add this in the code area. Also keep in mind to make sure the designer of that new control uses the same namespace "InfinityLabel". And one last thing, don't forget to set your new label (InfinityLabel) to BackColor=Transparent.

using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace InfinityLabel
{
    public partial class InfinityLabel : Label
    {
        public InfinityLabel()
        {
            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle rect = new Rectangle(0, 0, Width, Height);
            LinearGradientBrush brush =
                new LinearGradientBrush(
                    rect, 
                    Color.FromArgb(255, ForeColor),
                    Color.FromArgb(60, ForeColor), 
                    90f);
            e.Graphics.DrawString(Text, Font, brush, rect);
        }
    }
}