C # Common GDI + Text operations summary

Source: Internet
Author: User
This article summarizes the C # common GDI + text operations, including the text projection, reflection, rotation and other common effects, in the development of C # application has a good practical value. Share it for everyone's reference. Specific as follows:

First, the projection text

private void Form1_paint (object sender, PaintEventArgs e) {  //Projection text  Graphics g = this. CreateGraphics ();  Set the text output quality  g.textrenderinghint = Textrenderinghint.cleartypegridfit;  G.smoothingmode = Smoothingmode.antialias;  Font newFont = new Font ("Times New Roman", "$");  Matrix matrix = new Matrix ();  Project  Matrix. Shear ( -1.5f, 0.0f);  Zoom  Matrix. Scale (1, 0.5f);  Pan the  matrix. Translate (a);  Coordinate transformation, G.transform = matrix is applied to the drawing plane  ;  SolidBrush Graybrush = new SolidBrush (color.gray);  SolidBrush Colorbrush = new SolidBrush (color.blueviolet);  String text = "Mingrisoft";  Draw Shadow  g.drawstring (text, NewFont, Graybrush, new PointF (0));  G.resettransform ();  Draw foreground  g.drawstring (text, NewFont, Colorbrush, New PointF (0, 30));}

Second, the reflection of the text

private void Form1_paint (object sender, PaintEventArgs e) {  //Reflection text  Brush Backbrush = Brushes.gray;  Brush forebrush = brushes.black;  Font font = new Font ("Young Circle", convert.toint16 (+), fontstyle.regular);  Graphics g = this. CreateGraphics ();  String text = "Mingrisoft";  SizeF size = g.measurestring (text, font);  int PosX = (this. Width-convert.toint16 (size. Width)/2;  int PosY = (this. Height-convert.toint16 (size. Height))/2;  G.translatetransform (PosX, PosY);  int ascent = font. Fontfamily.getcellascent (font. Style);  int spacing = font. Fontfamily.getlinespacing (font. Style);  int lineheight = System.Convert.ToInt16 (font. GetHeight (g));  int height = lineheight * ascent/spacing;  GraphicsState state = G.save ();  G.scaletransform (1, -1.0f);  g.DrawString (text, font, Backbrush, 0,-height);  G.restore (state);  g.DrawString (text, font, forebrush, 0,-height);}

Three, the text fills the line

private void Form1_paint (object sender, PaintEventArgs e) {  //Use image to fill text lines  TextureBrush brush = new TextureBrush ( Image.FromFile (Application.startuppath + "\ \ Flower. jpg"));  Graphics g = e.graphics;  g.DrawString ("Mingrisoft", New Font ("Script", "Max"), Brush, new PointF (0, 0)); }

Four, rotate the text

private void Form1_paint (object sender, PaintEventArgs e) {  //rotate display text  graphics g = e.graphics;  G.smoothingmode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;  for (int i = 0; I <=; i + =)  {   //Translate the Graphics object to form center G.translatetransform (this). WIDTH/2, this. HEIGHT/2); Sets the output angle of the Graphics object G.rotatetransform (i); Set text fill color brush brush = brushes.darkviolet; Rotate the display text g.drawstring ("... Mingrisoft ", New Font (" Lucida Console ", 11f), brush, 0, 0); Restore Global Transformation matrix g.resettransform ();}  }

Five, the printing plate text

private void Form1_paint (object sender, PaintEventArgs e) {  //printing plate literal  int i = 0;  Brush Backbrush = brushes.black;  Brush forebrush = Brushes.violet;  Font font = new Font ("Times New Roman", System.Convert.ToInt16 (+), fontstyle.regular);  Graphics g = this. CreateGraphics ();  G.clear (color.white);  String text = "Mingrisoft";  SizeF size = g.measurestring (text, font);  Single PosX = (this. Width-convert.toint16 (size. Width)/2;  Single PosY = (this. Height-convert.toint16 (size. Height))/3;  while (I < convert.toint16)  {g.drawstring (text, font, Backbrush, posx-i, PosY + i); i = i + 1;  }  g.drawstring (text, font, Forebrush, PosX, PosY);}

It is believed that the examples mentioned in this paper will help everyone in C # programming.

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.