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#,谢谢了~~~

解决方案 »

  1.   

    前几天兔子发了个随机画曲线图  感觉不错的 发给你参考下
    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;
                //}
            }
        }
    }
      

  2.   

    为什么要用sleep,再用一个Timer试试