C#繪制中國(guó)國(guó)旗的方法
本文實(shí)例講述了C#繪制中國(guó)國(guó)旗的方法。分享給大家供大家參考。具體如下:
程序運(yùn)行截圖:
中國(guó)國(guó)旗被定義在《GB:12982-2004》中,以下是從維基百科條目中華人民共和國(guó)國(guó)旗中截的一張圖,標(biāo)出了五顆星大致的位置。
建立一個(gè)空的C# Windows窗體應(yīng)用程序,窗體取名FormMain,在窗體中放一個(gè)PictureBox,取名為picFlagOfChina,并將Dock屬性設(shè)置為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(); } //修改窗體大小時(shí)發(fā)生 private void FormMain_Resize(object sender, EventArgs e) { PaintFlag(); } /// <summary> /// 在圖片框 picFlagOfChina 中繪制國(guó)旗 /// </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)) }; } //農(nóng)民星 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個(gè)單位) 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)) }; } } }
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
相關(guān)文章
C#?wpf?通過(guò)HwndHost渲染視頻的實(shí)現(xiàn)方法
日常開(kāi)發(fā)中,特別是音視頻開(kāi)發(fā),需要在界面上渲染視頻,比如制作一個(gè)播放器、或者視頻編輯工具、以及視頻會(huì)議客戶端。通常拿到的是像素格式數(shù)據(jù),此時(shí)需要渲染到wpf窗口上就需要一定的方法,本文介紹一種通過(guò)hwnd渲染的方法,控件既能提供hwnd又能嵌入wpf窗口里2021-11-11解析C#中[],List,Array,ArrayList的區(qū)別及應(yīng)用
本篇文章主要是對(duì)C#中[],List,Array,ArrayList的區(qū)別及應(yīng)用進(jìn)行了詳細(xì)的介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-01-01c# List find()方法返回值的問(wèn)題說(shuō)明(返回結(jié)果為對(duì)象的指針)
本篇文章主要介紹了c#中List find()方法返回值的問(wèn)題說(shuō)明(返回結(jié)果為對(duì)象的指針) 需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-01-01c#擴(kuò)展datatable轉(zhuǎn)json示例
這篇文章主要介紹了c#擴(kuò)展datatable轉(zhuǎn)json示例,需要的朋友可以參考下2014-05-05winform實(shí)現(xiàn)限制及解除鼠標(biāo)移動(dòng)范圍的方法
這篇文章主要介紹了winform實(shí)現(xiàn)限制及解除鼠標(biāo)移動(dòng)范圍的方法,涉及C#控制WinForm鼠標(biāo)事件屬性的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09