博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#写点酷玩意,波形图控件
阅读量:4679 次
发布时间:2019-06-09

本文共 4243 字,大约阅读时间需要 14 分钟。

闲的没事,突然想起电影里那些高科技仪器,一个光点上下跳动,后面拉出精美的波形图,说干就干,

先来个效果:

我从来没写过这样的控件,所以关于某些算法都是自己想出来的,可能某些地方写的不好,还请大家指出。

 首先添加一个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; } } } }

 还要说一点,那个点是我用Ps出来的,目前没有什么好办法写出这种发光一样效果的圆,如果谁知道,留下来

转载于:https://www.cnblogs.com/1119242459blog/archive/2011/08/19/2146309.html

你可能感兴趣的文章
图片,base64 互转
查看>>
cache—主存—辅存三级调度模拟
查看>>
Java线程的定义
查看>>
Python-面向对象(组合、封装与多态)
查看>>
Mininet
查看>>
COSC2531 Programming Fundamentals
查看>>
设计模式系列 - 访问者模式
查看>>
20180507小测
查看>>
eclipse左侧不见
查看>>
python会缓存小的整数和短小的字符
查看>>
格网与四叉树索引
查看>>
多张照片拍摄、图片浏览
查看>>
html(5) css
查看>>
Azure Web连接到Azure MySql Db
查看>>
Linux shell 命令判断执行语法 ; , && , ||
查看>>
vim代码格式化插件clang-format
查看>>
What does the dot after dollar sign mean in jQuery when declaring variables?
查看>>
windows registry
查看>>
jquery 动画总结(主要指效果函数)
查看>>
leetcode-17-电话号码的字母组合’
查看>>