C# 实现用艺术效果显示文本的标签控件
2009-09-28 来自:CS 程序员之窗
- 摘要:C#实现边框、浮雕、印版效果显示文字的标签控件,可以改变边框的宽度和文字边框的颜色,实现绚丽的文字显示效果。
.NET自带的Label控件显示文本的形式非常单一,只能换换文本颜色、字体,用久了都觉得厌烦了。于是就实现了这个用艺术效果显示文本的标签控件ArtTextLabel,在这个控件中,我只实现了3种效果,其实还有很多其他效果都是可以实现的,大家可以试试。下面看看这3种效果的截图:
![ArtTextLabelDemo.png](http://www.csharpwin.com/upload/ArtTextLabelDemo.png)
实现这些效果其实很简单,就是稍微改变一下绘制文本的起始坐标,绘制几次就可以了,分别看看三种不同效果得绘制代码:
1、 边框。
private
void
RenderBordText(Graphics g, PointF point)
![ExpandedBlockStart.gif](http://www.csharpwin.com/Admin/fckeditor/editor/plugins/insertcode/images/ExpandedBlockStart.gif)
...
{
using (Brush brush = new SolidBrush(_borderColor))
![ExpandedSubBlockStart.gif](http://www.csharpwin.com/Admin/fckeditor/editor/plugins/insertcode/images/ExpandedSubBlockStart.gif)
...{
for (int i = 1; i <= _borderSize; i++)
![ExpandedSubBlockStart.gif](http://www.csharpwin.com/Admin/fckeditor/editor/plugins/insertcode/images/ExpandedSubBlockStart.gif)
...{
g.DrawString(
base.Text,
base.Font,
brush,
point.X - i,
point.Y);
g.DrawString(
base.Text,
base.Font,
brush,
point.X,
point.Y - i);
g.DrawString(
base.Text,
base.Font,
brush,
point.X + i,
point.Y);
g.DrawString(
base.Text,
base.Font,
brush,
point.X,
point.Y + i);
}
}
![InBlock.gif](http://www.csharpwin.com/Admin/fckeditor/editor/plugins/insertcode/images/InBlock.gif)
using (Brush brush = new SolidBrush(base.ForeColor))
![ExpandedSubBlockStart.gif](http://www.csharpwin.com/Admin/fckeditor/editor/plugins/insertcode/images/ExpandedSubBlockStart.gif)
...{
g.DrawString(
base.Text, base.Font, brush, point);
}
}
2、 浮雕。
private
void
RenderRelievoText(Graphics g, PointF point)
![ExpandedBlockStart.gif](http://www.csharpwin.com/Admin/fckeditor/editor/plugins/insertcode/images/ExpandedBlockStart.gif)
...
{
using (Brush brush = new SolidBrush(_borderColor))
![ExpandedSubBlockStart.gif](http://www.csharpwin.com/Admin/fckeditor/editor/plugins/insertcode/images/ExpandedSubBlockStart.gif)
...{
for (int i = 1; i <= _borderSize; i++)
![ExpandedSubBlockStart.gif](http://www.csharpwin.com/Admin/fckeditor/editor/plugins/insertcode/images/ExpandedSubBlockStart.gif)
...{
g.DrawString(
base.Text,
base.Font,
brush,
point.X + i,
point.Y);
g.DrawString(
base.Text,
base.Font,
brush,
point.X,
point.Y + i);
}
}
![InBlock.gif](http://www.csharpwin.com/Admin/fckeditor/editor/plugins/insertcode/images/InBlock.gif)
using (Brush brush = new SolidBrush(base.ForeColor))
![ExpandedSubBlockStart.gif](http://www.csharpwin.com/Admin/fckeditor/editor/plugins/insertcode/images/ExpandedSubBlockStart.gif)
...{
g.DrawString(
base.Text, base.Font, brush, point);
}
}
3、 印版。
private
void
RenderFormeText(Graphics g, PointF point)
![ExpandedBlockStart.gif](http://www.csharpwin.com/Admin/fckeditor/editor/plugins/insertcode/images/ExpandedBlockStart.gif)
...
{
using (Brush brush = new SolidBrush(_borderColor))
![ExpandedSubBlockStart.gif](http://www.csharpwin.com/Admin/fckeditor/editor/plugins/insertcode/images/ExpandedSubBlockStart.gif)
...{
for (int i = 1; i <= _borderSize; i++)
![ExpandedSubBlockStart.gif](http://www.csharpwin.com/Admin/fckeditor/editor/plugins/insertcode/images/ExpandedSubBlockStart.gif)
...{
g.DrawString(
base.Text,
base.Font,
brush,
point.X - i,
point.Y + i);
}
}
![InBlock.gif](http://www.csharpwin.com/Admin/fckeditor/editor/plugins/insertcode/images/InBlock.gif)
using (Brush brush = new SolidBrush(base.ForeColor))
![ExpandedSubBlockStart.gif](http://www.csharpwin.com/Admin/fckeditor/editor/plugins/insertcode/images/ExpandedSubBlockStart.gif)
...{
g.DrawString(
base.Text, base.Font, brush, point);
}
}
声明:
本文版权归作者和CS 程序员之窗所有,欢迎转载,转载必须保留以下版权信息,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
作者:Starts_2000
出处:CS 程序员之窗 http://www.csharpwin.com。
你可以免费使用或修改提供的源代码,但请保留源代码中的版权信息,详情请查看:
CS
程序员之窗开源协议 http://www.csharpwin.com/csol.html。
转载于:https://www.cnblogs.com/AsionTang/archive/2010/05/22/1741488.html