国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#繪制中國國旗的方法

2020-01-24 01:32:57
字體:
來源:轉載
供稿:網友

本文實例講述了C#繪制中國國旗的方法。分享給大家供大家參考。具體如下:

程序運行截圖:

中國國旗被定義在《GB:12982-2004》中,以下是從維基百科條目中華人民共和國國旗中截的一張圖,標出了五顆星大致的位置。

建立一個空的C# Windows窗體應用程序,窗體取名FormMain,在窗體中放一個PictureBox,取名為picFlagOfChina,并將Dock屬性設置為Fill。程序代碼中用到了窗體事件Load和Resize,程序代碼如下:

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace ChineseFlag{ public partial class FormMain : Form {  public FormMain()  {   InitializeComponent();  }  private void FormMain_Load(object sender, EventArgs e)  {   PaintFlag();  }  //修改窗體大小時發生  private void FormMain_Resize(object sender, EventArgs e)  {   PaintFlag();  }  /// <summary>  /// 在圖片框 picFlagOfChina 中繪制國旗  /// </summary>  private void PaintFlag()  {   picFlagOfChina.BackColor = Color.Red;   picFlagOfChina.Image = new Bitmap(    picFlagOfChina.Width, picFlagOfChina.Height);   Graphics g = Graphics.FromImage(picFlagOfChina.Image);   Point[] p = new Point[] { };   p = PentacleA(this.Width, this.Height);   g.FillPolygon(Brushes.Yellow, p);   p = PentacleB(this.Width, this.Height);   g.FillPolygon(Brushes.Yellow, p);   p = PentacleC(this.Width, this.Height);   g.FillPolygon(Brushes.Yellow, p);   p = PentacleD(this.Width, this.Height);   g.FillPolygon(Brushes.Yellow, p);   p = PentacleE(this.Width, this.Height);   g.FillPolygon(Brushes.Yellow, p);  }  //大星  private Point[] PentacleA(int width, int height)  {   return new Point[]    {     new Point((int)(width / 30.0 * 5), (int)(height / 20.0 * 2)),    new Point((int)(width / 30.0 * 5.7), (int)(height / 20.0 * 4.1)),    new Point((int)(width / 30.0 * 8), (int)(height / 20.0 * 4.1)),    new Point((int)(width / 30.0 * 6), (int)(height / 20.0 * 5.3)),    new Point((int)(width / 30.0 * 6.8), (int)(height / 20.0 * 7.3)),    new Point((int)(width / 30.0 * 5), (int)(height / 20.0 * 6.1)),    new Point((int)(width / 30.0 * 3.2), (int)(height / 20.0 * 7.3)),    new Point((int)(width / 30.0 * 4), (int)(height / 20.0 * 5.3)),    new Point((int)(width / 30.0 * 2), (int)(height / 20.0 * 4.1)),    new Point((int)(width / 30.0 * 4.3), (int)(height / 20.0 * 4.1)),   };  }  //工人星  private Point[] PentacleB(int width, int height)  {   return new Point[]    {     new Point((int)(width / 30.0 * 9.2), (int)(height / 20.0 * 2.5)),    new Point((int)(width / 30.0 * 9.6), (int)(height / 20.0 * 2)),    new Point((int)(width / 30.0 * 9.3), (int)(height / 20.0 * 1.4)),    new Point((int)(width / 30.0 * 9.95), (int)(height / 20.0 * 1.7)),    new Point((int)(width / 30.0 * 10.45), (int)(height / 20.0 * 1.1)),    new Point((int)(width / 30.0 * 10.36), (int)(height / 20.0 * 1.85)),    new Point((int)(width / 30.0 * 11), (int)(height / 20.0 * 2.1)),    new Point((int)(width / 30.0 * 10.34), (int)(height / 20.0 * 2.25)),    new Point((int)(width / 30.0 * 10.3), (int)(height / 20.0 * 2.95)),    new Point((int)(width / 30.0 * 9.9), (int)(height / 20.0 * 2.3))   };  }  //農民星  private Point[] PentacleC(int width, int height)  {   return new Point[]    {     new Point((int)(width / 30.0 * 11), (int)(height / 20.0 * 4.1)),    new Point((int)(width / 30.0 * 11.65), (int)(height / 20.0 * 3.8)),    new Point((int)(width / 30.0 * 11.55), (int)(height / 20.0 * 3.05)),    new Point((int)(width / 30.0 * 12.05), (int)(height / 20.0 * 3.6)),    new Point((int)(width / 30.0 * 12.7), (int)(height / 20.0 * 3.3)),    new Point((int)(width / 30.0 * 12.35), (int)(height / 20.0 * 3.98)),    new Point((int)(width / 30.0 * 12.9), (int)(height / 20.0 * 4.5)),    new Point((int)(width / 30.0 * 12.1), (int)(height / 20.0 * 4.3)),    new Point((int)(width / 30.0 * 11.8), (int)(height / 20.0 * 5)),    new Point((int)(width / 30.0 * 11.7), (int)(height / 20.0 * 4.2))   };  }  //小資星  private Point[] PentacleD(int width, int height)  {   return new Point[]    {     new Point((int)(width / 30.0 * 11.1), (int)(height / 20.0 * 6.7)),    new Point((int)(width / 30.0 * 11.8), (int)(height / 20.0 * 6.7)),    new Point((int)(width / 30.0 * 12), (int)(height / 20.0 * 6)),    new Point((int)(width / 30.0 * 12.2), (int)(height / 20.0 * 6.7)),    new Point((int)(width / 30.0 * 12.9), (int)(height / 20.0 * 6.7)),    new Point((int)(width / 30.0 * 12.35), (int)(height / 20.0 * 7.1)),    new Point((int)(width / 30.0 * 12.55), (int)(height / 20.0 * 7.8)),    new Point((int)(width / 30.0 * 12), (int)(height / 20.0 * 7.4)),    new Point((int)(width / 30.0 * 11.45), (int)(height / 20.0 * 7.8)),    new Point((int)(width / 30.0 * 11.65), (int)(height / 20.0 * 7.1))   };  }  //民資星(工人星向下平移7個單位)  private Point[] PentacleE(int width, int height)  {   return new Point[]    {     new Point((int)(width / 30.0 * 9.2), (int)(height / 20.0 * 9.5)),    new Point((int)(width / 30.0 * 9.6), (int)(height / 20.0 * 9)),    new Point((int)(width / 30.0 * 9.3), (int)(height / 20.0 * 8.4)),    new Point((int)(width / 30.0 * 9.95), (int)(height / 20.0 * 8.7)),    new Point((int)(width / 30.0 * 10.45), (int)(height / 20.0 * 8.1)),    new Point((int)(width / 30.0 * 10.36), (int)(height / 20.0 * 8.85)),    new Point((int)(width / 30.0 * 11), (int)(height / 20.0 * 9.1)),    new Point((int)(width / 30.0 * 10.34), (int)(height / 20.0 * 9.25)),    new Point((int)(width / 30.0 * 10.3), (int)(height / 20.0 * 9.95)),    new Point((int)(width / 30.0 * 9.9), (int)(height / 20.0 * 9.3))   };  } }}

希望本文所述對大家的C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 鹤岗市| 大关县| 贵定县| 维西| 华亭县| 霞浦县| 广宁县| 芦溪县| 全南县| 遂宁市| 黄大仙区| 旅游| 贵南县| 芜湖市| 太和县| 会昌县| 翁牛特旗| 周宁县| 阳城县| 芜湖市| 勐海县| 康马县| 湖南省| 印江| 永丰县| 都兰县| 临汾市| 嘉祥县| 广东省| 逊克县| 万年县| 衢州市| 文成县| 平陆县| 神池县| 长顺县| 荃湾区| 鄂托克旗| 内黄县| 岚皋县| 紫金县|