2016年8月31日 星期三
由txt檔讀取數值繪製波形
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;
using System.IO;
namespace HRV_波形
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
float ff;
List<int> ii = new List<int>();//動態陣列
private void Form1_Load(object sender, EventArgs e)
{
StreamReader sr = new StreamReader(@"E:\raw.txt");
//===一次讀取全部內容===
string a = sr.ReadToEnd();
richTextBox1.Text = a;//顯示在textbox
sr.Close();
//
sr = new StreamReader(@"E:\raw.txt");
string line;
List<string> iii = new List<string>();
while (!sr.EndOfStream)//一次讀一行(一個值)
{
line = sr.ReadLine();
iii.Add(line);
}
for (int aaa = 0; aaa < iii.Count; aaa++)//由字串轉成數值
{
if (iii[aaa] != "" && iii[aaa] != null)
ii.Add(int.Parse(iii[aaa]));
}
sr.Close();
//設定panel大小
panel2.Width = ii.Count * 2;
panel2.Height = panel1.Height;
ff = panel1.Height / 260;
}
private void panel2_Paint(object sender, PaintEventArgs e)
{
Graphics g = panel2.CreateGraphics();
//
List<Point> MyPoint = new List<Point>();
Pen Mypen = new Pen(Color.Blue);
Point p = new Point();
for (int b = 0; b < ii.Count; b++)
{
int c = ii[b];
p.X = b;
p.Y = 250 - c;
MyPoint.Add(p);
}
for (int b = 1; b < MyPoint.Count; b++)
{
g.DrawLine(Mypen, MyPoint[b - 1], MyPoint[b]);
}
}
private void button1_Click(object sender, EventArgs e)
{
panel2.Invalidate();//重繪
}
}
}
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言