private void DrawContent(ref Graphics picGraphics, float[][] lineValue, Color[] lineColor)
{
//t.SynchronizingObject = ;
System.Timers.Timer t = new System.Timers.Timer(5000);
t.AutoReset = true;
t.Enabled = true;
t.Elapsed += new System.Timers.ElapsedEventHandler(theout); int length1 = 0, length2 = 0;
if (lineValue == null)
return;
if (lineValue.Length >= 1)
{
CurveSortGetMax(LineValueAll);
float OffsetY1 = XYO.Y;
float OffsetY2 = YSlice / YSliceValue;
float xKeys = 0;
float yKeysValues = 0;
PointF[][] CurvePointF = new PointF[lineValue.Length][];
for ( int i = 0; i < lineValue.Length; i++)
{
if (lineValue[i].Length <= xPointScaleNum )
{
CurvePointF[i] = new PointF[lineValue[i].Length];
Pen CurvePen;
if (i < lineColor.Length)
CurvePen = new Pen(lineColor[i], 1);
else
{
int n;
Random ra = new Random();
n = ra.Next(0, lineColor.Length);
CurvePen = new Pen(lineColor[n], 1);
} for ( int j = 0; j < lineValue[i].Length; j++)
{
xKeys = XSlice * j + XYO.X;
yKeysValues = OffsetY1 - (lineValue[i][j] - YSliceBegin) * OffsetY2;
CurvePointF[i][j] = new PointF(xKeys, yKeysValues); //画点
objGraphics.FillEllipse(Brushes.White, xKeys, yKeysValues, 8, 8);//
//timer = new System.Threading.Timer(new TimerCallback(CheckStatus), null, 0, 5000);
// 输出坐标点数据
//objGraphics.DrawString(lineValue[i][j].ToString(), new Font("宋体", 10), new SolidBrush(TextColor), xKeys-4, yKeysValues-4);
}
// 绘制折线
objGraphics.DrawCurve(CurvePen, CurvePointF[i], Tension);
}
else
{
MessageBox.Show("有曲线点数超限!");
}
}
while (length2 < CurvePointF[length1].Length)
{
paint(objGraphics, CurvePointF[0][length2].X, CurvePointF[0][length2].Y);
paint(objGraphics,CurvePointF[1][length2].X, CurvePointF[1][length2].Y );
length2++; }
}
}
我想在画点函数那实现每2秒钟画一个点,但是用Sleep的话一运行就死了。大家谁会这方面的,帮我解答一下,最好是给我点代码看看,小弟也是初学c#,谢谢了~~~
{
//t.SynchronizingObject = ;
System.Timers.Timer t = new System.Timers.Timer(5000);
t.AutoReset = true;
t.Enabled = true;
t.Elapsed += new System.Timers.ElapsedEventHandler(theout); int length1 = 0, length2 = 0;
if (lineValue == null)
return;
if (lineValue.Length >= 1)
{
CurveSortGetMax(LineValueAll);
float OffsetY1 = XYO.Y;
float OffsetY2 = YSlice / YSliceValue;
float xKeys = 0;
float yKeysValues = 0;
PointF[][] CurvePointF = new PointF[lineValue.Length][];
for ( int i = 0; i < lineValue.Length; i++)
{
if (lineValue[i].Length <= xPointScaleNum )
{
CurvePointF[i] = new PointF[lineValue[i].Length];
Pen CurvePen;
if (i < lineColor.Length)
CurvePen = new Pen(lineColor[i], 1);
else
{
int n;
Random ra = new Random();
n = ra.Next(0, lineColor.Length);
CurvePen = new Pen(lineColor[n], 1);
} for ( int j = 0; j < lineValue[i].Length; j++)
{
xKeys = XSlice * j + XYO.X;
yKeysValues = OffsetY1 - (lineValue[i][j] - YSliceBegin) * OffsetY2;
CurvePointF[i][j] = new PointF(xKeys, yKeysValues); //画点
objGraphics.FillEllipse(Brushes.White, xKeys, yKeysValues, 8, 8);//
//timer = new System.Threading.Timer(new TimerCallback(CheckStatus), null, 0, 5000);
// 输出坐标点数据
//objGraphics.DrawString(lineValue[i][j].ToString(), new Font("宋体", 10), new SolidBrush(TextColor), xKeys-4, yKeysValues-4);
}
// 绘制折线
objGraphics.DrawCurve(CurvePen, CurvePointF[i], Tension);
}
else
{
MessageBox.Show("有曲线点数超限!");
}
}
while (length2 < CurvePointF[length1].Length)
{
paint(objGraphics, CurvePointF[0][length2].X, CurvePointF[0][length2].Y);
paint(objGraphics,CurvePointF[1][length2].X, CurvePointF[1][length2].Y );
length2++; }
}
}
我想在画点函数那实现每2秒钟画一个点,但是用Sleep的话一运行就死了。大家谁会这方面的,帮我解答一下,最好是给我点代码看看,小弟也是初学c#,谢谢了~~~
解决方案 »
- 如何用PC接收分析移动/联通发来的信息
- 如何通过正则表达式提取出img标签
- c#如何实现泛型链表
- 从网络下载数据的疑问,高手指点!
- 简单问题.熟悉dataset的进来看看...
- 水晶报表里面的方本框长度固定,如何在文本超出文本框时改变文本框内字体的大小让文本全部显示出来?
- c# dataSet操作xml文件问题。
- 关于transaction manager 的功能阻止问题,着急,在线等,谢谢!
- C#在数据库中存取图片?
- system.windows.forms.mdiclient是什么东东?怎么引入到项目中?
- 求博客加好友功能,最近访客功能,送礼物功能源码(现金300块)
- bitmap.UnlockBits(BitmapData)出错
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication7
{
public partial class Form5 : Form
{
List<Point> Points = new List<Point>();
Bitmap OrgBmp = null;
int Start = 0;
Random R = new Random();
PictureBox PB = new PictureBox(); public Form5()
{
InitializeComponent(); PB.Parent = this;
PB.Dock = DockStyle.Fill; OrgBmp = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height);
using (Graphics G = Graphics.FromImage(OrgBmp))
{
G.Clear(Color.Black);
G.DrawString("随机曲线图", this.Font, Brushes.Green, new PointF(0, 0));
} PB.Image = OrgBmp; Timer T = new Timer();
T.Interval = 100;
T.Tick += new EventHandler(T_Tick);
T.Enabled = true; } void T_Tick(object sender, EventArgs e)
{
Bitmap CacheBmp = new Bitmap(OrgBmp);
Points.Add(new Point(Start++ * 5, 150 - R.Next(100))); if (Points.Count > 1)
using (Graphics G = Graphics.FromImage(CacheBmp))
G.DrawCurve(Pens.Red, Points.ToArray()); PB.Image = CacheBmp;
//if (Start == 10)
//{
// (sender as Timer).Enabled = false;
//}
}
}
}