C Word of Art Class Instance Code

  • 2021-09-11 21:05:05
  • OfStack

No more nonsense, just give you the code. The specific code is as follows:

The code is as follows:


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// This is 1 Wordart control 
{ 
// Text attribute 
private string _text = "WordArt";
public string Caption
{
get { return _text; }
set { _text = value; }
}
// Font and size 
private Font _WordArtFont = new Font(" Song Style ",15);
public Font WordArtFont
{
get { return _WordArtFont; }
set { _WordArtFont = value; }
}
// Color 
private Color _WordArtForeColor = Color.BlueViolet;
public Color WordArtForeColor
{
get { return _WordArtForeColor; }
set { _WordArtForeColor = value; }
}
// Color of Shadow 
private Color _WordArtBackColor = Color.Gray;
public Color WordArtBackColor
{
set { _WordArtBackColor = value; }
get { return _WordArtBackColor; }
}
// Text output quality: rendering mode and smoothing effect 
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();
}
// The form of artistic characters : Shadow , Embossed … 
private WordArtEffectStyle _WordArtEffect=WordArtEffectStyle.projection;// Projection is the default form ;
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:// Projection effect 
// Setting Text Output Quality 
g.TextRenderingHint = this.WordArtTextRenderingHint;
g.SmoothingMode = this.WordArtSmoothingMode;
Matrix matrix = new Matrix();
// Projection 
matrix.Shear(-1.5f, 0.0f);
// Zoom 
matrix.Scale(1, 0.5f);
// Translation 
matrix.Translate(120, 75);
// Transform the coordinates of the drawing plane 
g.Transform = matrix;

This is the end of the code, I hope it will be helpful to everyone!


Related articles: