资 源 简 介
C# 为文字创建渐变色的下划线,放大后还是很漂亮的,下划线变成了点状的,而且是颜色是渐变的,下面介绍实现这一功能的代码,给字符串创建渐变色下划线,核心代码如下:
TextDecoration MyUnderline = new TextDecoration();
Pen MyPen = new Pen();
MyPen.Brush = new LinearGradientBrush(Colors.Green,
Colors.Blue, new Point(0, 0.5), new Point(1, 0.5));
MyPen.Brush.Opacity = 0.5;
MyPen.Thickness = 1.5;
MyPen.DashStyle = DashStyles.Dash;
MyUnderline.Pen = MyPen;
MyUnderline.PenThicknessUnit = TextDecorationUnit.FontRecommended;
TextDecorationCollection MyCollection = new TextDecorationCollection();
MyCollection.Add(MyUnderline);
this.textBlock1.Text = "中华人民共和国";//自定义要显示下划线的文字
this.textBlock1.FontSize = 48;
this.textBlock1.TextDecorations = MyCollection;
需要请下载完整源码。运行效果图如下。