当前位置:编程学习 > C#/ASP.NET >>

C#之形状原点变换代码

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Drawing.Drawing2D;
  9. namespace advanced_drawing
  10. {
  11.     public partial class Form7 : Form
  12.     {
  13.         public Form7()
  14.         {
  15.             InitializeComponent();
  16.         }
  17.         void DrawLabelRect(Graphics g, string label)
  18.         {
  19.             Rectangle rect = new Rectangle(0, 0, 125, 125);
  20.             StringFormat format = new StringFormat();
  21.             format.Alignment = StringAlignment.Center;
  22.             format.LineAlignment = StringAlignment.Center;
  23.             g.FillRectangle(Brushes.White, rect);
  24.             g.DrawRectangle(Pens.Black, rect.X, rect.Y, rect.Width, rect.Height);
  25.             g.DrawString(label, this.Font, Brushes.Black, rect, format);
  26.         }
  27.         private void Form7_Paint(object sender, PaintEventArgs e)
  28.         {
  29.             Graphics g = e.Graphics;
  30.             DrawLabelRect(g, "zhuzhao");
  31.             Matrix matrix = new Matrix();
  32.             matrix.Translate(150, 150);
  33.             g.Transform = matrix;
  34.             DrawLabelRect(g, "zhuzhao123");
  35.         }
  36.     }
  37. }
补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,