C#波形图控件制作示例程序
发布时间:2022-02-24 21:50:40
首先添加一个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;
}
}
}
}


猜你喜欢
- 出处:https://www.cnblogs.com/SunSpringeclipse下面创建的Maven项目,使用mybatis。ecli
- 题意Description相信大家都做过"A+B Problem"了吧,这道题是它的加强版。输入两个整数 A , B ,
- 目录事件最基本的用法理解路由事件WPF中使用路由事件升级了传统应用开发中的事件,在WPF中使用路由事件能更好的处理事件相关的逻辑,我们从这篇
- 线程可以有六种状态:1.New(新创建)2.Runnable(可运行)(运行)3.Blocked(被阻塞)4.Waiting(等待)5.Ti
- 前几篇主要集中在注册中心eureka的使用上,接下来可以创建服务提供者provider来注册到eureka。demo源码见: https:/
- 一、使用mybatis-spring-boot-starter1、添加依赖<dependency> <grou
- Redisson分布式锁之前的基于注解的锁有一种锁是基本redis的分布式锁,锁的实现我是基于redisson组件提供的RLock,这篇来看
- DataHub 类似于传统大数据解决方案中 Kafka 的角色,提供了一个数据队列功能。DataHub 除了供了一个缓冲的队列作用。同时由于
- 一、堆的创建1、向下调整(以小堆为例) 让parent标记需要调整的节点,child标记parent的左孩子(注意:parent
- 网上的解决方法:这个是从网上看来的file-->setting-->plugins,搜索tomcat然后install之后会提示
- 自己的一个小项目使用redis在一个类里可以注入成功,而在另一个类以却不能注入成功不多bb直接上代码package com.common.u
- android原生的Spinner提供了下拉列表选项框,但在一些流行的APP中,原生的Spinner似乎不太受待见,而通常会有下图所示的下拉
- 本文实例讲述了Android实现的简单蓝牙程序。分享给大家供大家参考,具体如下:我将在这篇文章中介绍了的Android蓝牙程序。这个程序就是
- 1.背景Java语言相比于C和C++,一个最大的特点就是不需要程序员自己手动去申请和释放内存,这一切交由JVM来完成。在Java中,运行时的
- 1、IO流1.流和流的分类什么是IO流?I:Input (输入)O: Ouput(输出)IO流的分类?有多种分类方式:一种方式是按照流的方向
- 一、概述最近在群里听到各种讨论okhttp的话题,可见okhttp的口碑相当好了。再加上Google貌似在6.0版本里面删除了HttpCli
- using System;using System.Web;using System.Web.Security;namespace Auth
- 前言今天的文章从下面这张图片开始,这张图片Java开发们应该很熟悉了我们都知道无锁状态是对象头是有位置存储hashcode的,而变为偏向锁状
- 前言最近面试时,面试官问了一个列表倒计时效果如何实现,然后脑袋突然懵的了O(∩_∩)O,现在记录一下。运行效果图实现思路实现方法主要有两个:
- 本文实例讲述了C#实现对Json字符串处理方法,分享给大家供大家参考。具体分析如下:一般对于web应用开发人员来说对Json字符串都会很熟悉