在C#用Graphics绘制图形(雪人)

来源:互联网 发布:水池计算软件 编辑:程序博客网 时间:2024/04/28 13:08

 

在网上看到一段代码,觉得有意思,

程序运行图

在看代码:

 

view plaincopy to clipboardprint?
  1. private void printDramC(Graphics g)   
  2. {   
  3.     const int MID = 150;   
  4.     const int Top = 50;   
  5.     this.Text = "simple graphics snowman";   
  6.   
  7.     Font font = new Font("隶书",17);   
  8.   
  9.     Pen blue = new Pen(Color.Blue);   
  10.     Pen yellow = new Pen(Color.Yellow);   
  11.     Pen white = new Pen(Color.White);   
  12.     Pen red = new Pen(Color.Red);   
  13.     Pen black = new Pen(Color.Black);   
  14.     Brush brWhite = white.Brush;   
  15.     Brush brBlack = black.Brush;   
  16.     Brush brRed = red.Brush;   
  17.   
  18.     g.FillRectangle(brRed, 20, 30, 30, 120);   
  19.     g.FillRectangle(brRed, 250, 30, 30, 120);   
  20.     g.FillRectangle(brRed, 100, 0, 100, 25);   
  21.   
  22.     StringFormat format = new StringFormat();   
  23.     format.FormatFlags = StringFormatFlags.DirectionVertical;   
  24.   
  25.     g.DrawString("三杯祝福歌", font, brBlack, 250, 30, format);   
  26.     g.DrawString("一曲迎春调", font, brBlack, 20, 30, format);   
  27.     g.DrawString("迎春祝福", font, brBlack, 100, 0);   
  28.   
  29.     g.DrawRectangle(blue, 0, 175, 300, 50);  //sky   
  30.     g.DrawEllipse(yellow, -40, -40, 80, 80); //sun   
  31.     g.FillEllipse(brWhite, MID - 20, Top, 40, 40); //head   
  32.     g.FillEllipse(brWhite, MID - 35, Top + 35, 70, 50); //top   
  33.     g.FillEllipse(brWhite, MID - 50, Top + 80, 100, 60); //bot   
  34.     g.FillEllipse(brBlack, MID - 10, Top + 10, 5, 5); //l.eye   
  35.     g.FillEllipse(brBlack, MID + 5, Top + 10, 5, 5);//r.eye   
  36.     g.DrawArc(black, MID - 10, Top + 20, 20, 10, -190, -160);//(:   
  37.     //arms   
  38.     g.DrawLine(black, MID - 25, Top + 60, Top - 50, MID + 40);   
  39.     g.DrawLine(black, MID + 25, Top + 60, MID + 55, Top + 60);   
  40.   
  41.     g.DrawLine(black, MID - 20, Top + 5, MID + 20, Top + 5);//hat,brim,top   
  42.     g.FillRectangle(brBlack, MID - 15, Top - 20, 30, 25);   
  43. }  

 

原创粉丝点击