C#编写的艺术字类实例代码
废话不多说了,直接给大家上代码了,具体代码如下所示:
代码如下:
usingSystem; usingSystem.Collections.Generic; usingSystem.ComponentModel; usingSystem.Drawing; usingSystem.Drawing.Text; usingSystem.Drawing.Drawing2D; usingSystem.Data; usingSystem.Text; usingSystem.Windows.Forms; publicpartialclassWordArt:UserControl//这是一个艺术字的控件 { //文本属性 privatestring_text="WordArt"; publicstringCaption { get{return_text;} set{_text=value;} } //字体以及大小 privateFont_WordArtFont=newFont("宋体",15); publicFontWordArtFont { get{return_WordArtFont;} set{_WordArtFont=value;} } //颜色 privateColor_WordArtForeColor=Color.BlueViolet; publicColorWordArtForeColor { get{return_WordArtForeColor;} set{_WordArtForeColor=value;} } //阴影的颜色 privateColor_WordArtBackColor=Color.Gray; publicColorWordArtBackColor { set{_WordArtBackColor=value;} get{return_WordArtBackColor;} } //文本输出质量:呈现模式和平滑效果 privateTextRenderingHint_TextRenderingHint=TextRenderingHint.ClearTypeGridFit; publicTextRenderingHintWordArtTextRenderingHint { get{return_TextRenderingHint;} set{_TextRenderingHint=value;} } publicSmoothingMode_SmoothingMode=SmoothingMode.AntiAlias; publicSmoothingModeWordArtSmoothingMode { get{return_SmoothingMode;} set{_SmoothingMode=value;} } publicWordArt() { InitializeComponent(); } //艺术字的形式:阴影,浮雕…… privateWordArtEffectStyle_WordArtEffect=WordArtEffectStyle.projection;//投影为默认形式; publicWordArtEffectStyleWordArtEffect { get{return_WordArtEffect;} set{_WordArtEffect=value;} } protectedoverridevoidOnPaint(PaintEventArgse) { base.OnPaint(e); Graphicsg=this.CreateGraphics(); BrushbackBrush=newSolidBrush(this.WordArtBackColor); BrushforeBrush=newSolidBrush(this.WordArtForeColor); SizeFsize=g.MeasureString(this.Caption,this.WordArtFont); SingleposX=(this.Width-Convert.ToInt16(size.Width))/2; SingleposY=(this.Height-Convert.ToInt16(size.Height))/2; switch(this.WordArtEffect) { caseWordArtEffectStyle.projection://投影效果 //设置文本输出质量 g.TextRenderingHint=this.WordArtTextRenderingHint; g.SmoothingMode=this.WordArtSmoothingMode; Matrixmatrix=newMatrix(); //投射 matrix.Shear(-1.5f,0.0f); //缩放 matrix.Scale(1,0.5f); //平移 matrix.Translate(120,75); //对绘图平面坐标实施变换 g.Transform=matrix;
代码到此结束了,希望对大家有所帮助!