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

首先添加一個(gè)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保證了滾動(dòng)時(shí)最右側(cè)垂直線及時(shí)出現(xiàn)
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.未標(biāo)題_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;//滾動(dòng)就靠他了,是一個(gè)范圍
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("抖動(dòng)率,值控件輸入的值自動(dòng)抖動(dòng)(禁用是為0)"),Category("屬性值")]
public int Shake
{
get{return shake;}
set{shake = value;}
}
[DefaultValue(0),Description("當(dāng)前數(shù)值"),Category("屬性值")]
public int Value
{
get { return lightPointValue; }
set { lightPointValue = value; }
}
[Description("當(dāng)前數(shù)值"), 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;
}
}
}
}
相關(guān)文章
C#?WPF?ListBox?動(dòng)態(tài)顯示圖片功能
這篇文章主要介紹了C#?WPF?ListBox?動(dòng)態(tài)顯示圖片,處理過程分為前臺(tái)代碼和后臺(tái)代碼,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2023-08-08
asp.net獲取系統(tǒng)當(dāng)前時(shí)間的方法詳解
這篇文章主要介紹了asp.net獲取系統(tǒng)當(dāng)前時(shí)間的方法,較為詳細(xì)的分析了C#日期與時(shí)間操作所涉及的相關(guān)函數(shù)與使用技巧,需要的朋友可以參考下2016-06-06
.net2.0+ Winform項(xiàng)目實(shí)現(xiàn)彈出容器層
在實(shí)際工作中,如果能像菜單一樣彈出自定義內(nèi)容,會(huì)方便很多,比如查詢時(shí),比如下拉列表顯示多列信息時(shí),比如在填寫某個(gè)信息需要查看一些信息樹時(shí)。這個(gè)時(shí)候自定義彈出界面就顯的非常重要了2015-08-08
舊項(xiàng)目升級(jí)新版Unity2021導(dǎo)致Visual?Studio無(wú)法使用的問題
在項(xiàng)目開發(fā)過程中,不可避免的會(huì)升級(jí)開發(fā)工具。這次我在舊項(xiàng)目版本升級(jí)到新版Unity2021.2.x時(shí),出現(xiàn)Visual?Studio無(wú)法定位等問題,這里我給大家分享下解決方法,舊項(xiàng)目升級(jí)新版Unity2021導(dǎo)致Visual?Studio無(wú)法使用的問題,需要的朋友可以參考下2021-12-12

