SoFunction
Updated on 2025-03-07

Summary of commonly used GDI+text operations in C#

The examples in this article summarize the commonly used GDI+ text operations in C#, including common effects such as projection, reflection, and rotation of text, which has good practical value in C# application development. Share it for your reference. The details are as follows:

1. Projection text

private void Form1_Paint(object sender, PaintEventArgs e)
{
  //Projection text  Graphics g = ();
  //Set text output quality   = ;
   = ;
  Font newFont = new Font("Times New Roman", 48);
  Matrix matrix = new Matrix();
  //projection  (-1.5f, 0.0f);
  //Zoom  (1, 0.5f);
  //Platform  (130, 88);
  //Implement coordinate transformation on the drawing plane,   = matrix;
  SolidBrush grayBrush = new SolidBrush();
  SolidBrush colorBrush = new SolidBrush();
  string text = "MINGRISOFT";
  //Draw shadow  (text, newFont, grayBrush, new PointF(0, 30));
  ();
  //Draw the foreground  (text, newFont, colorBrush, new PointF(0, 30));
}

2. Reflection text

private void Form1_Paint(object sender, PaintEventArgs e)
{
  //Reflection text  Brush backBrush = ;
  Brush foreBrush = ;
  Font font = new Font("Young round", Convert.ToInt16(40), );
  Graphics g = ();
  string text = "MINGRISOFT";
  SizeF size = (text, font);
  int posX = ( - Convert.ToInt16()) / 2;
  int posY = ( - Convert.ToInt16()) / 2;
  (posX, posY);
  int ascent = ();
  int spacing = ();
  int lineHeight = .ToInt16((g));
  int height = lineHeight * ascent / spacing;
  GraphicsState state = ();
  (1, -1.0F);
  (text, font, backBrush, 0, -height);
  (state);
  (text, font, foreBrush, 0, -height);
}

3. Text fill lines

private void Form1_Paint(object sender, PaintEventArgs e)
{
  //Fill text lines with images  TextureBrush brush = new TextureBrush(( + "\\Flower.jpg"));
  Graphics g = ;
  ("MINGRISOFT", new Font("Lishu", 60), brush, new PointF(0, 0)); 
}

4. Rotate the text

private void Form1_Paint(object sender, PaintEventArgs e)
{
  //Rotate the text to display  Graphics g = ;
   = .;
  for (int i = 0; i <= 360; i += 10)
  {  
 //Pank the Graphics object to the center of the form ( / 2,  / 2);
 //Set the output angle of Graphics object (i);
 //Set text fill color Brush brush = ;
 //Rotate the text to display ("......MINGRISOFT", new Font("Lucida Console", 11f), brush, 0, 0);
 //Restore the global transformation matrix ();
  }
}

5. Printing plate text

private void Form1_Paint(object sender, PaintEventArgs e)
{
  //Printing text  int i = 0;
  Brush backBrush = ;
  Brush foreBrush = ;
  Font font = new Font("Times New Roman", .ToInt16(40), );
  Graphics g = ();
  ();
  string text = "MINGRISOFT";
  SizeF size = (text, font);
  Single posX = ( - Convert.ToInt16()) / 2;
  Single posY = ( - Convert.ToInt16()) / 3;
  while (i < Convert.ToInt16(20))
  {
 (text, font, backBrush, posX - i, posY + i);
 i = i + 1;
  }
  (text, font, foreBrush, posX, posY);
}

I believe that the examples described in this article will be of some help to everyone's C# programming.