InBlock.gif     public Bitmap mybitmap; //用于双缓冲的位图,和画布等大
InBlock.gif
InBlock.gif                Random rm = new Random(); //随机数产生器
InBlock.gif
InBlock.gif                 public void DrawLineS(Color color, float Xmax, float Ymax, PictureBox picbox, Point[] ptlist)
InBlock.gif                {
InBlock.gif                        mybitmap = new Bitmap(picbox.Width, picbox.Height); //设定位图大小
InBlock.gif                        Graphics doublebufferg = Graphics.FromImage(mybitmap); //从位图上获取“画布”
InBlock.gif                        doublebufferg.Clear(Color.White); //用背景色刷新
InBlock.gif
InBlock.gif                         //pictureBox1填充为白色,便于显示图像    500*300
InBlock.gif                        Rectangle rect = new Rectangle(0, 0, picbox.Width, picbox.Height);
InBlock.gif                        doublebufferg.FillRectangle( new SolidBrush(Color.White), rect);
InBlock.gif
InBlock.gif
InBlock.gif                         //画X和Y轴
InBlock.gif                        DrawXY( ref doublebufferg, picbox);
InBlock.gif                         //X轴上的刻度
InBlock.gif                        SetYAxis( ref doublebufferg, picbox, Ymax);
InBlock.gif                         //Y轴上的刻度
InBlock.gif                        SetXAxis( ref doublebufferg, picbox, Xmax);
InBlock.gif
InBlock.gif                         //要显示的实时曲线部分
InBlock.gif                        Point temp = new Point();
InBlock.gif                         for ( int j = 0; j < picbox.Width / 5 - 1; j++)
InBlock.gif                        {
InBlock.gif                                temp = ptlist[j + 1];
InBlock.gif                                ptlist[j] = new Point(temp.X - 5, temp.Y);
InBlock.gif                        }
InBlock.gif
InBlock.gif                        Point lastpt = new Point();
InBlock.gif                        lastpt.X = picbox.Width;
InBlock.gif                        lastpt.Y = (picbox.Height -30) -Convert.ToInt32(atemp_mun)*5 ;
InBlock.gif
InBlock.gif                        ptlist[picbox.Width / 5 - 1] = lastpt;
InBlock.gif                        doublebufferg.DrawLines( new Pen(color, 1), ptlist);
InBlock.gif
InBlock.gif
InBlock.gif                         //将缓冲中的位图绘制到我们的窗体上
InBlock.gif                        Graphics g1 = picbox.CreateGraphics(); //创建 PictureBox窗体的画布
InBlock.gif
InBlock.gif                        g1.Clear(Color.White);
InBlock.gif                        g1.DrawImage(mybitmap, 0, 0);
InBlock.gif
InBlock.gif                }
InBlock.gif
InBlock.gif
InBlock.gif                 //完成X轴和Y轴的基本部分
InBlock.gif                 public void DrawXY( ref Graphics g, PictureBox picbox)
InBlock.gif                {
InBlock.gif                        Pen pen = new Pen(Color.Black, 2); //画笔
InBlock.gif                        Pen pen_heigh = new Pen(Color.Red, 1); //画笔
InBlock.gif                        Pen pen_low = new Pen(Color.Gray, 1); //画笔
InBlock.gif                        SolidBrush sb = new SolidBrush(Color.Black); //话刷
InBlock.gif                        SolidBrush sb2 = new SolidBrush(Color.Gray); //话刷
InBlock.gif
InBlock.gif                         //X轴的箭头,实际上是绘制了一个三角形
InBlock.gif                        Point[] xpts = new Point[3] {    
InBlock.gif                                 new Point(picbox.Width - 35, picbox.Height - 32),
InBlock.gif                                 new Point(picbox.Width - 35, picbox.Height - 28),    
InBlock.gif                                 new Point(picbox.Width - 30, picbox.Height - 30)    
InBlock.gif                                                                                 };
InBlock.gif
InBlock.gif                        g.DrawLine(pen, 40, picbox.Height - 30, picbox.Width - 30, picbox.Height - 30);
InBlock.gif                        g.DrawPolygon(pen, xpts);
InBlock.gif                        g.DrawString( "取样点", new Font( "宋体", 9), sb, picbox.Width - 55, picbox.Height - 45);
InBlock.gif
InBlock.gif                         //画上上限温度:e
InBlock.gif                        g.DrawLine(pen_heigh, 40, picbox.Height - heigh_temp*5 - 30, picbox.Width - 5, picbox.Height - heigh_temp*5 - 30);
InBlock.gif                        g.DrawString( "上限温度" + heigh_temp.ToString() + "℃", new Font( "宋体", 8), sb, picbox.Width - 80, picbox.Height - heigh_temp * 5 - 45);
InBlock.gif                         //画上下限温度:
InBlock.gif                        g.DrawLine(pen_low, 40, picbox.Height - low_temp * 5 - 30, picbox.Width -5, picbox.Height - low_temp * 5 - 30);
InBlock.gif                        g.DrawString( "下限温度" + low_temp.ToString() + "℃", new Font( "宋体", 8), sb, picbox.Width - 80, picbox.Height - low_temp * 5 - 45);
InBlock.gif                         //Y轴的箭头,实际上是绘制了一个三角形
InBlock.gif                        Point[] ypts = new Point[3] {    
InBlock.gif                                         new Point(7, 15),    
InBlock.gif                                         new Point(1, 10),    
InBlock.gif                                         new Point(3, 15) };
InBlock.gif
InBlock.gif                        g.DrawLine(pen, 1, picbox.Height - 30, 1, 10);
InBlock.gif                        g.DrawPolygon(pen, ypts);
InBlock.gif                        g.DrawString( "实时温度℃", new Font( "宋体", 9), sb, 14, 10);
InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif                }
InBlock.gif
InBlock.gif
InBlock.gif                 //绘制Y轴上的刻度25-35
InBlock.gif                 public void SetYAxis( ref Graphics g, PictureBox picbox, float YMAX)
InBlock.gif                {
InBlock.gif                        Pen p1 = new Pen(Color.Goldenrod, 1);
InBlock.gif                        Pen p2 = new Pen(Color.Black, 2);
InBlock.gif                        SolidBrush sb = new SolidBrush(Color.Black);
InBlock.gif
InBlock.gif                         float ykedu = YMAX / 200; //给定的最大刻度与实际像素的比例关系
InBlock.gif
InBlock.gif                         //第一个刻度的两个端点
InBlock.gif                         float xl = 27, yl = picbox.Height - 30, yr = picbox.Height - 30;
InBlock.gif
InBlock.gif                         for ( int j = 0; j < picbox.Height - 60; j += 10)
InBlock.gif                        {
InBlock.gif
InBlock.gif                                 if (j % 50 == 0) //一个大的刻度,黑色,每隔50像素一个
InBlock.gif                                {
InBlock.gif                                        g.DrawLine(p2, xl, yl - j, 2, yl - j); //刻度线
InBlock.gif                                         string tempy = (j * ykedu).ToString();
InBlock.gif                                        g.DrawString(tempy, new Font( "宋体", 8), sb, 30, yl - j - 5);
InBlock.gif                                }
InBlock.gif                                 else //小刻度,金×××,10像素一个
InBlock.gif                                { g.DrawLine(p1, 10, yl - j, 20, yl - j); }
InBlock.gif                        }
InBlock.gif                }