a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 編程 > C# > 正文

C#波形圖控件制作示例程序

2020-01-24 03:02:57
字體:
來源:轉載
供稿:網友


首先添加一個timer,50s

復制代碼 代碼如下:

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

namespace High_Tech_Watch
{
    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
        }

        int[] oldLine;
        int SIZE = 15; //方格的大小
        Pen LINEPEN = new Pen(Color.FromArgb(3,64, 129), 1); //背景線條顏色
        Pen FORELINEPEN = new Pen(Color.LightBlue);  //前景線條顏色
        private void UserControl1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            int Bvalue;
            Bvalue = Value;
            if (shake != 0)
            {
                Random ro = new Random();
                int r = ro.Next(0, shake);
                Value += (ro.Next(-shake, 0) / 2) + r/2;
                if (Value>100)
                {
                    Value = 100;
                }
                if (Value < 0)
                {
                    Value = 0;
                }
            }
            int h = (int)(this.Size.Height / SIZE);
            int w = (int)(this.Size.Width / SIZE )+ 1;//這里加1保證了滾動時最右側垂直線及時出現
            for (; h >= 0;h-- )
            {
                g.DrawLine(LINEPEN, new Point(0, h * SIZE), new Point(this.Size.Width, h * SIZE));
            }
            for (; w>=0;w-- )
            {
                g.DrawLine(LINEPEN, new Point((w * SIZE) - limits, 0), new Point((w * SIZE) - limits, this.Size.Height));
            }
            for (int i = oldLine.Length - 1,j = 0;i >j ;j++ )
            {
                g.DrawLine(FORELINEPEN, new Point(j,(this.Height - (int)(((float)oldLine[j] / (float)100) * (float)this.Height) ) -1),
                    new Point(j + 1, (this.Height - (int)(((float)oldLine[j+1] / (float)100) * (float)this.Height))-1) );
            }
            for (int i = oldLine.Length - 1, j = 0; i > j; j++)
            {
                oldLine[j] = oldLine[j + 1];
            }
            oldLine[oldLine.Length - 1] = Value;
            pintLightPoint(e);
            Value = Bvalue;
        }

        private void pintLightPoint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.DrawImage(global::High_Tech_Watch.Resource1.未標題_2,new Rectangle(new Point(this.Width - 50,this.Height - (int)(((float)lightPointValue / (float)100) * (float)this.Height ) - 10),new Size(20,20)));

        }

        int lightPointValue = 50;
        int limits = 0;//滾動就靠他了,是一個范圍
        private void timer1_Tick(object sender, EventArgs e)
        {
            limits++;
            if (limits >= SIZE)
            {
                limits = 0;
            }
            this.Invalidate();
        }

        private void UserControl1_Load(object sender, EventArgs e)
        {

            oldLine = new int[this.Width - 40];

        }

        int shake = 0;
        [DefaultValue(0),Description("抖動率,值控件輸入的值自動抖動(禁用是為0)"),Category("屬性值")]
        public int Shake
        {
            get{return shake;}
            set{shake = value;}
        }
        [DefaultValue(0),Description("當前數值"),Category("屬性值")]
        public int Value
        {
            get { return lightPointValue; }
            set { lightPointValue = value; }
        }
        [Description("當前數值"), Category("屬性值")]
        public Pen LinePen
        {
            get { return LINEPEN; }
            set
            {
                LINEPEN = value;
                this.Invalidate();
            }
        }

        private void UserControl1_Resize(object sender, EventArgs e)
        {

            if ((this.Width - 40) > oldLine.Length)
            {
                 int[] newArry = new int[this.Width - 40];
                oldLine.CopyTo(newArry, newArry.Length - oldLine.Length);
                oldLine = new int[this.Width - 40];
                oldLine = newArry;
            }
            if ((this.Width - 40) < oldLine.Length)
            {
                int[] newArry = new int[this.Width - 40];
                for (int i = newArry.Length - 1,j = oldLine.Length - 1; i >=0 ;i--,j-- )
                {
                   newArry[i] = oldLine[j];
                }
                oldLine = new int[this.Width - 40];
                oldLine = newArry;
            }

        }
    }
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久久精品视频偷拍 | 国产在线一区二区三区 | jvid美女成人福利视频 | 亚洲一区久久久 | 一区二区三区免费网站 | 国产精品久久久麻豆 | 一级黄色片子免费看 | 成人在线免费观看 | a中文在线视频 | 欧美在线视频播放 | 国产拍拍视频 | 久久久国产一区二区三区四区小说 | 成人精品高清 | 成人乱淫av日日摸夜夜爽节目 | 蜜臀av性久久久久av蜜臀妖精 | 日韩视频在线一区 | 精品国产不卡一区二区三区 | 久草视频新 | 一区二区三区影院 | av性色 | 午夜av免费 | xoxo国产三区精品欧美 | 久久久久高清 | 91精品国产色综合久久不卡98口 | 91精品久久久久久久久久入口 | 呦呦精品 | 国产精品一线二线三线 | 久久国产精品99久久久久久牛牛 | 最新久久精品 | 一区二区三区国产 | 激情国产 | 九九综合九九综合 | 久久久久国产精品午夜一区 | 成人在线免费 | 日韩激情影院 | 国产精品一区二区三区网站 | 亚洲综合国产激情另类一区 | 自拍偷拍视频网站 | 日本做暖暖视频高清观看 | 国产福利在线视频 | 男人久久天堂 |