C # implement the tag Control for displaying text with artistic effects from: CS programmer window
- Abstract: C # implements the label control of text display based on the border, relief, and printing plate effects. It can change the Border width and the color of the text border to achieve brilliant text display effects.
The label control provided by. Net has a single display text format. It can only be used to change the text color and font. After a long time, I feel bored. As a result, arttextlabel, a tag control that displays text with artistic effects, is implemented. In this control, I only implement three effects. In fact, many other effects can be achieved, you can try it. Let's take a look at the three effects:
The implementation of these effects is actually very simple, that is, to slightly change the starting coordinate of the text to be drawn several times, respectively look at three different effects to draw the Code:
1. Border.
private void RenderBordText(Graphics g, PointF point)
...{
using (Brush brush = new SolidBrush(_borderColor))
...{
for (int i = 1; i <= _borderSize; 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);
g.DrawString(
base.Text,
base.Font,
brush,
point.X + i,
point.Y);
g.DrawString(
base.Text,
base.Font,
brush,
point.X,
point.Y + i);
}
}
using (Brush brush = new SolidBrush(base.ForeColor))
...{
g.DrawString(
base.Text, base.Font, brush, point);
}
}
2. Relief.
private void RenderRelievoText(Graphics g, PointF point)
...{
using (Brush brush = new SolidBrush(_borderColor))
...{
for (int i = 1; i <= _borderSize; 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);
}
}
using (Brush brush = new SolidBrush(base.ForeColor))
...{
g.DrawString(
base.Text, base.Font, brush, point);
}
}
3. printing plate.
private void RenderFormeText(Graphics g, PointF point)
...{
using (Brush brush = new SolidBrush(_borderColor))
...{
for (int i = 1; i <= _borderSize; i++)
...{
g.DrawString(
base.Text,
base.Font,
brush,
point.X - i,
point.Y + i);
}
}
using (Brush brush = new SolidBrush(base.ForeColor))
...{
g.DrawString(
base.Text, base.Font, brush, point);
}
}
Statement:
The copyright of this article is owned by the author and the CS programmer. You are welcome to repost it. You must retain the following copyright information and provide the original article connection clearly on the article page. Otherwise, you will be held legally liable.
Author: starts_2000
Source: CS programmer window http://www.csharpwin.com.
You can use or modify the provided source code for free, but keep the copyright information in the source code. For more information, see:
Open-source protocol for CS programmers: http://www.csharpwin.com/csol.html.