五星红旗是由红色背景,加5个黄色五角星组成。绘制一个五星红旗的思路,就是先定义一个五角星的自定义控件,然后通过设置五角星的大小、位置、旋转角度等属性,组合成一个五星红旗。

五角星自定义控件代码:

public partial class MyStar : Control
{
public MyStar()
{
InitializeComponent();
} protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe); Graphics g = pe.Graphics;
PointF[] points = new PointF[]
{
new PointF(Center.X, Center.Y - Radius),
new PointF((float)(Center.X + Radius * Math.Sin( * Math.PI / )), (float)(Center.Y - Radius * Math.Cos( * Math.PI / ))),
new PointF((float)(Center.X + Radius * Math.Sin( * Math.PI / )), (float)(Center.Y + Radius * Math.Cos(* Math.PI / ))),
new PointF((float)(Center.X - Radius * Math.Sin( * Math.PI / )),(float)( Center.Y + Radius * Math.Cos( * Math.PI / ))), new PointF((float)(Center.X - Radius * Math.Sin( * Math.PI / )), (float)(Center.Y - Radius * Math.Cos( * Math.PI / ))),
}; GraphicsPath path = new GraphicsPath(FillMode.Winding);
path.AddLine(points[], points[]);
path.AddLine(points[], points[]);
path.AddLine(points[], points[]);
path.AddLine(points[], points[]);
path.AddLine(points[], points[]);
path.CloseFigure(); g.SmoothingMode = SmoothingMode.AntiAlias;
g.RotateTransform(Angle);
g.FillPath(new SolidBrush(ColorTranslator.FromHtml("#FFDF00")), path);
} /// <summary>
/// 中心点
/// </summary>
public Point Center { get; set; } /// <summary>
/// 半径
/// </summary>
public int Radius { get; set; } /// <summary>
/// 旋转角度
/// </summary>
public float Angle { get; set; }
}

如上的Center、Radius、Angle都是public类型暴露出来的公共属性,以便在初始化时动态的设置MyStar相关属性。

然后创建一个窗体(450*300),并拖动一个Panel容器。

在VS中编译后会在工具栏生成MyStar控件,我们在窗体的Load事件中动态的添加MyStar控件即可。

private void Form1_Load(object sender, EventArgs e)
{
this.panel1.BackColor = Color.Red; MyStar c1 = new MyStar();
c1.Angle = 0F;
c1.Location = new System.Drawing.Point(, );
c1.Size = new System.Drawing.Size(, );
c1.Center = new Point(, );
c1.Radius = ; MyStar c2 = new MyStar();
c2.Angle = 20F;
c2.Location = new System.Drawing.Point(, -);
c2.Size = new System.Drawing.Size(, );
c2.Center = new Point(, );
c2.Radius = ; MyStar c3 = new MyStar();
c3.Angle = -20F;
c3.Location = new System.Drawing.Point(, );
c3.Size = new System.Drawing.Size(, );
c3.Center = new Point(, );
c3.Radius = ; MyStar c4 = new MyStar();
c4.Angle = 0F;
c4.Location = new System.Drawing.Point(, );
c4.Size = new System.Drawing.Size(, );
c4.Center = new Point(, );
c4.Radius = ; MyStar c5 = new MyStar();
c5.Angle = 20F;
c5.Location = new System.Drawing.Point(, );
c5.Size = new System.Drawing.Size(, );
c5.Center = new Point(, );
c5.Radius = ; this.panel1.Controls.Add(c1);
this.panel1.Controls.Add(c2);
this.panel1.Controls.Add(c3);
this.panel1.Controls.Add(c4);
this.panel1.Controls.Add(c5); this.panel1.Click += (ss, ee) => { this.Close(); };
}

效果图:

GDI+绘制五星红旗的更多相关文章

  1. 通过GDI+绘制 验证码

    只为了记录下自己的学习历程,方便日后查看 现在开始言归正传,以下为其完整代码附上 using System; using System.Collections.Generic; using Syste ...

  2. Html5 绘制五星红旗

    Html5+JavaScript 在Canvas上绘制五星红旗,具体思路如下图所示: 绘制思路在上图中已有说明,具体代码如下: <script type="text/javascrip ...

  3. C#利用GDI+绘制旋转文字等效果

    C#中利用GDI+绘制旋转文本的文字,网上有很多资料,基本都使用矩阵旋转的方式实现.但基本都只提及按点旋转,若要实现在矩形范围内旋转文本,资料较少.经过琢磨,可以将矩形内旋转转化为按点旋转,不过需要经 ...

  4. C# 使用GDI+绘制漂亮的MenuStrip和ContextMenuStrip皮肤

    通过上面的效果截图可以看到,重绘后的MenuStrip和ContextMenuStrip可以添加自己的LOGO信息,实现了类似OFFICE2007的菜单显示效果. .NET对菜单控件的绘制提供了一个抽 ...

  5. HTML5 canvas 绘制五星红旗

    这个例子并不是自己写的,在网上找的案列,仿照写的,,,自己真的公布董这些算法,看完这个例子还是有一点模糊,,, 如果谁看的比较明白,指点一下,,,多谢!!!! <!doctype html> ...

  6. MFC 用gdi绘制填充多边形区域

    MFC 用gdi绘制填充多边形区域 这里的代码是实现一个三角形的绘制,并用刷子填充颜色 在OnPaint()函数里面 运用的是给定的三角形的三个点,很多个点可以绘制多边形 CBrush br(RGB( ...

  7. GDI绘制时钟效果,与系统时间保持同步,基于Winform

    2018年工作之余,想起来捡起GDI方面的技术,特意在RichCodeBox项目中做了两个示例程序,其中一个就是时钟效果,纯C#开发.这个CSharpQuartz是今天上午抽出一些时间,编写的,算是偷 ...

  8. 『备注』GDI+ 绘制文本有锯齿,透明背景文本绘制

    背景: GDI+ 绘制文本 时,如果 背景是透明的 —— 则会出现 锯齿. //其实,我不用这三个 属性 好多年了 //而且,这三个属性 在关键时刻还有可能 帮倒忙 //关键是:这三个属性,鸟用都没有 ...

  9. C#GDI+ 绘制线段(实线或虚线)、矩形、字符串、圆、椭圆

    C#GDI+ 绘制线段(实线或虚线).矩形.字符串.圆.椭圆 绘制基本线条和图形 比较简单,直接看代码. Graphics graphics = e.Graphics; //绘制实线 )) { pen ...

随机推荐

  1. 你真的会用Gson吗?Gson使用指南(2)

    注:此系列基于Gson 2.4. 上一篇文章 你真的会用Gson吗?Gson使用指南(1) 我们了解了Gson的基础用法,这次我们继续深入了解Gson的使用方法. 本次的主要内容: Gson的流式反序 ...

  2. Apache Kafka学习 (二) - 多代理(broker)集群

    1. 配置server.properties > cp config/server.properties config/server-1.properties> cp config/ser ...

  3. ConcurrentLinkedQueue代码解析

    原因:学习ConcurrentLinkedQueue是看到akka框架的默认邮箱是使用ConcurrentLinkedQueue实现的. 1. ConcurrentLinkedQueue在java.u ...

  4. Linux中安装绿色软件的方法

    一.简介 我们平时安装软件时,想要把一个可直接运行的软件及其依赖库Copy到Linux中的某个文件夹下.但是为了快速方便地执行它,不想每次都进入此目录中执行.解决的方法是向PATH中相关的路径下投放软 ...

  5. Vue加载组件、动态加载组件的几种方式

    https://cn.vuejs.org/v2/guide/components.html https://cn.vuejs.org/v2/guide/components-dynamic-async ...

  6. 【微信上传素材接口--永久性】微信永久性上传、获取返回的medie_id 和url

    上传图片到微信服务器获得media_id和url (永久性) 其他接口类:https://www.cnblogs.com/gjw-hsf/p/7375261.html 转载地址:https://blo ...

  7. LightCapture for Mac(流程化截图工具)破解版安装

    1.软件简介    LightCapture 是 macOS 系统上的截图软件.LightCapture Mac 版号称是用最简洁的方式来截图,其的界面也确实非常简单整洁,不过功能同样出色,一键截屏. ...

  8. springboot1.5.4 log4j

    resources下面添加: log4j.properties: # log4j.rootCategory=INFO, stdout, file, errorfile log4j.category.c ...

  9. 实战c++中的vector系列--vector&lt;unique_ptr&lt;&gt;&gt;初始化(全部权转移)

    C++11为我们提供了智能指针,给我们带来了非常多便利的地方. 那么假设把unique_ptr作为vector容器的元素呢? 形式如出一辙:vector<unique_ptr<int> ...

  10. 9.5 翻译系列:数据注解之ForeignKey特性【EF 6 Code-First系列】

    原文链接:https://www.entityframeworktutorial.net/code-first/foreignkey-dataannotations-attribute-in-code ...