基本信息
源码名称:C# 动态绘制曲线
源码大小:0.30M
文件格式:.rar
开发语言:C#
更新时间:2020-07-10
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 3 元 
   源码介绍


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 绘制曲线
{
    public partial class Form1 : Form
    {

        //随机数
        private static int iSeed = 8;
        Random rd = new Random(iSeed);

        //存放数据的数组最大值
        private int sizeMax;
        //存放y轴数据的数组链表
        private List<int> DataL;
        //存放在画布上的数据节点的数组
        private Point[] pArrData;

        public Form1()
        {
            InitializeComponent();

            //根据画布的宽决定x轴需要多少个数组
            sizeMax = pcbDisplay.Width / 2;
            //数据数组
            DataL = new List<int>();
            pArrData = new Point[sizeMax   1];
        }

        //private void pcbDisplay_Click(object sender, EventArgs e)
        //{

        //}

        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            DataL.Add(rd.Next(20, 180));
            //数据链表是否达到x轴最大容量的数组(动态曲线的来源)
            if (DataL.Count == sizeMax   2)
            {
                DataL.RemoveAt(0);//移除链表第一个
            }

            //判断数据链表是否为空
            if (DataL.Count != 0)
            {
                pArrData = new Point[DataL.Count];
            }

            //生成新的节点
            for (int i = 0; i < sizeMax   1; i  )
            {
                if (i >= DataL.Count)
                {
                    break;
                }
                pArrData[i] = new Point(i * 2, DataL[i]);
            }
            pcbDisplay.Refresh();
        }

        #region 绘制曲线

        //定义画笔
        private Pen greenPen = new Pen(Color.Green, 1);
        private Pen redPen = new Pen(Color.Red, 1);
        private Pen blackPen = new Pen(Color.Black, 1);

        /// <summary>
        /// 绘制曲线
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void pcbDisplay_Paint(object sender, PaintEventArgs e)
        {
            if (DataL.Count != 1)
            {
                e.Graphics.DrawCurve(greenPen, pArrData);
            }
        }
        #endregion
    }
}