方法一:将事件放在form_Load中,在窗体中画图
 
   1:          protected void MainForm_Load(object sender,EventArgs e)
   2:          {
   3:              InitialPoint();        
   4:              Bitmap bm = new Bitmap(this.Width,this.Height);
   5:              Graphics grp = Graphics.FromImage(bm);
   6:              DrawCurves(grp,lpt);
   7:              pictureBox1.Image =bm;
   8:              //if use load event,then use bitmap,if not ,there is no need.
   9:   
  10:          }

方法二:利用picturebox画图,放在Load事件中。

   1:          protected void MainForm_Load(object sender,EventArgs e)
   2:          {
   3:              InitialPoint();        
   4:              Bitmap bm = new Bitmap(pictureBox1.Width,pictureBox1.Height);
   5:              pictureBox1.Image =bm;
   6:              using(Graphics grp =Graphics.FromImage(pictureBox1.Image))
   7:              {
   8:                  DrawCurves(grp,lpt);
   9:              }
  10:   
  11:          }

方法三:将事件放在Paint事件中,这个只能放在form中,因为grp本例和e无关,但是参数是:PaintEventArgs e

   1:          private void Form1_Paint(object sender, PaintEventArgs e)
   2:          {
   3:              //if in this method,there is no need to use bitmap
   4:              InitialPoint();    
   5:              Graphics grp =this.CreateGraphics();
   6:              DrawCurves(grp,lpt);        
   7:          }


方法四:paint事件,在picturebox上,按照下边这个例子,用e这个参数,不仅可以放在form的paint上,也可以放在picturebox的paint上

 
 

   1:          private void pic_paint(object sender,PaintEventArgs e)
   2:          {
   3:               Graphics g = e.Graphics;
   4:               DrawCurves(g,lpt);
   5:          }

   1:          private void DrawCurves(Graphics grp, List<Point> pointList)
   2:          {
   3:              Point[] temps = new Point[pointList.Count];
   4:              pointList.CopyTo(temps);
   5:              grp.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
   6:              grp.DrawCurve(new Pen(Color.Red, 2), temps);
   7:             // grp.Dispose();如果用Paint事件绘图,这个似乎不可以
   8:          }

注明:lpt是一个List<Point>

最新文章

  1. linux基本知识0
  2. cygwin和mingw的区别
  3. c#中高效的excel导入sqlserver的方法
  4. Bmob开发指南【android端】
  5. boa服务器make错误
  6. linux下共享内存mmap和DMA(直接访问内存)的使用 【转】
  7. HTML4 和 HTML5 的10个关键区别
  8. IIS OCIEnvCreate failed with return code -1
  9. 机器学习&amp;深度学习经典资料汇总,data.gov.uk大量公开数据
  10. Hdu5517 Triple
  11. jQuery源码笔记——延迟对象
  12. hibernate的通配符比拼接sql到底好在哪?
  13. php生成html 伪静态??
  14. selenium 学习之路开始了,一遍搬一遍理解学习,加油!!!
  15. selenium的八大定位元素的方式
  16. 手写JavaScript常用的函数
  17. python 绘图pylab
  18. js版的in_array的实现方法
  19. Linux下安装Hadoop
  20. 利用python同步windows和linux文件

热门文章

  1. Extjs 实用——不定时更新
  2. NHibernate分页
  3. START167 AND BOOT167
  4. Could not load the assembly &#39;App_Web_cwclgcuu&#39;. Make sure that it is compiled before accessing the page.
  5. .cmd文件不小心管理记事本打开的恢复
  6. [Angular2 Form] Use RxJS Streams with Angular 2 Forms
  7. jQuery代码性能小细节
  8. SSD(固态硬盘)简介
  9. 程序的内存分配 C\C++
  10. js json与对象的相互转换