欢迎来到入门教程网!

C#教程

当前位置:主页 > 软件编程 > C#教程 >

C#编写的艺术字类实例代码

来源:本站原创|时间:2020-01-10|栏目:C#教程|点击:

废话不多说了,直接给大家上代码了,具体代码如下所示:

代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Text;
using System.Drawing.Drawing2D;
using System.Data;
using System.Text;
using System.Windows.Forms;
public partial class WordArt : UserControl//这是一个艺术字的控件
{ 
//文本属性
private string _text = "WordArt";
public string Caption
{
get { return _text; }
set { _text = value; }
}
//字体以及大小
private Font _WordArtFont = new Font("宋体",15);
public Font WordArtFont
{
get { return _WordArtFont; }
set { _WordArtFont = value; }
}
//颜色
private Color _WordArtForeColor = Color.BlueViolet;
public Color WordArtForeColor
{
get { return _WordArtForeColor; }
set { _WordArtForeColor = value; }
}
//阴影的颜色
private Color _WordArtBackColor = Color.Gray;
public Color WordArtBackColor
{
set { _WordArtBackColor = value; }
get { return _WordArtBackColor; }
}
//文本输出质量:呈现模式和平滑效果
private TextRenderingHint _TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
public TextRenderingHint WordArtTextRenderingHint
{
get { return _TextRenderingHint; }
set { _TextRenderingHint = value; }
}
public SmoothingMode _SmoothingMode = SmoothingMode.AntiAlias;
public SmoothingMode WordArtSmoothingMode
{
get { return _SmoothingMode; }
set { _SmoothingMode = value; }
}
public WordArt()
{
InitializeComponent();
}
//艺术字的形式:阴影,浮雕……
private WordArtEffectStyle _WordArtEffect=WordArtEffectStyle.projection;//投影为默认形式;
public WordArtEffectStyle WordArtEffect
{
get { return _WordArtEffect; }
set { _WordArtEffect = value; }
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = this.CreateGraphics();
Brush backBrush=new SolidBrush(this.WordArtBackColor);
Brush foreBrush=new SolidBrush(this.WordArtForeColor);
SizeF size = g.MeasureString(this.Caption, this.WordArtFont);
Single posX = (this.Width - Convert.ToInt16(size.Width)) / 2;
Single posY = (this.Height - Convert.ToInt16(size.Height)) / 2;
switch (this.WordArtEffect)
{
case WordArtEffectStyle.projection://投影效果
//设置文本输出质量
g.TextRenderingHint = this.WordArtTextRenderingHint;
g.SmoothingMode = this.WordArtSmoothingMode;
Matrix matrix = new Matrix();
//投射
matrix.Shear(-1.5f, 0.0f);
//缩放
matrix.Scale(1, 0.5f);
//平移
matrix.Translate(120, 75);
//对绘图平面坐标实施变换
g.Transform = matrix;

代码到此结束了,希望对大家有所帮助!

上一篇:C#利用GDI绘制常见图形和文字

栏    目:C#教程

下一篇:C#微信公众平台开发之高级群发接口

本文标题:C#编写的艺术字类实例代码

本文地址:https://www.xiuzhanwang.com/a1/C_jiaocheng/6623.html

网页制作CMS教程网络编程软件编程脚本语言数据库服务器

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:835971066 | 邮箱:835971066#qq.com(#换成@)

Copyright © 2002-2020 脚本教程网 版权所有