baidu_36304836 2016-10-15 03:24 采纳率: 0%
浏览 754

我的C#窗体要拉一下才能刷出图形,怎么办啊

是想实现点一下画一个五角星图案,小白求助。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    int startX = 0;
    int  startY = 0;
    private void Form1_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            startX = e.X;
            startY = e.Y;
        }

        MessageBox.Show("坐标: " + Convert.ToString(startX) +"  ,  "+ Convert.ToString(startY));
    }

    protected override void OnPaint(PaintEventArgs e)
    {
       Point center = new Point(startX,startY);
      //绘制五角星
        int radius = 100;
        PointF[] pentagons = new PointF[] { new PointF(center.X, center.Y - radius),
            new PointF((float)(center.X + radius * Math.Sin(72 * Math.PI / 180)), (float)(center.Y - radius * Math.Cos(72 * Math.PI / 180))),
            new PointF((float)(center.X + radius * Math.Sin(36 * Math.PI / 180)), (float)(center.Y + radius * Math.Cos(36* Math.PI / 180))),
            new PointF((float)(center.X - radius * Math.Sin(36 * Math.PI / 180)),(float)( center.Y + radius * Math.Cos(36 * Math.PI / 180))),
            new PointF((float)(center.X - radius * Math.Sin(72 * Math.PI / 180)), (float)(center.Y - radius * Math.Cos(72 * Math.PI / 180))),
        };


        GraphicsPath path = new GraphicsPath(FillMode.Winding);
        path.AddLine(pentagons[0], pentagons[2]);
        path.AddLine(pentagons[2], pentagons[4]);
        path.AddLine(pentagons[4], pentagons[1]);
        path.AddLine(pentagons[1], pentagons[3]);
        path.AddLine(pentagons[3], pentagons[0]);
        path.CloseFigure();

        e.Graphics.FillPath(Brushes.Red, path);
        path.Dispose();

    }



}

}

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-10-15 03:29
    关注

    在formload里调用下this.Refreash

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?