C # method of writing wordart

Source: Internet
Author: User

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 A WordArt Control
{
// Text attributes
Private string _ text = "WordArt ";
Public string Caption
{
Get {return _ text ;}
Set {_ text = value ;}
}
// Font and size
Private Font _ WordArtFont = new Font ("", 15 );
Public Font WordArtFont
{
Get {return _ WordArtFont ;}
Set {_ WordArtFont = value ;}
}
// Color
Private Color _ WordArtForeColor = Color. bluevilet;
Public Color WordArtForeColor
{
Get {return _ WordArtForeColor ;}
Set {_ WordArtForeColor = value ;}
}
// Shadow color
Private Color _ WordArtBackColor = Color. Gray;
Public Color WordArtBackColor
{
Set {_ WordArtBackColor = value ;}
Get {return _ WordArtBackColor ;}
}
// Text output quality: rendering mode and smooth 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 ();
}
// Form of artistic words: Shadow, embossed ......
Private WordArtEffectStyle _ WordArtEffect = WordArtEffectStyle. projection; // The default projection format is used;
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
// Set the 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 plane coordinate of the Drawing
G. Transform = matrix;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.