C#绘制中国国旗的方法
程序员文章站
2023-12-04 23:22:34
本文实例讲述了c#绘制中国国旗的方法。分享给大家供大家参考。具体如下:
程序运行截图:
中国国旗被定义在《gb:12982-2004》中,以下是从*条目中华人...
本文实例讲述了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#程序设计有所帮助。