时间:2021-05-20
本文实例讲述了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#程序设计有所帮助。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文是利用C#实现中国象棋的棋盘绘制,以及初始化布局,并不实现中国象棋的对弈逻辑。仅供学习参考使用。思路:绘制中国象棋棋盘,竖线九条,横线十条。再中间绘制‘楚河
之前我们介绍过word绘制国旗的方法,今天我们就来看看使用word的形状绘制古巴国旗的教程。软件名称:Office2016专业增强版中文免费正式版(附安装教程)
本文实例讲述了C#利用GDI+绘制旋转文字等效果的方法,是非常实用的技巧。分享给大家供大家参考之用。具体如下:C#中利用GDI+绘制旋转文本的文字,网上有很多资
电脑只有word的时候,想要使用word绘制国旗,该怎么绘制科摩罗国旗呢?下面我们就来看看详细的教程。软件名称:MicrosoftOffice2019正式版中文
本文实例讲述了C#绘制椭圆的方法。分享给大家供大家参考。具体实现方法如下:usingSystem;usingSystem.Collections.Generic