用Drawing画图如何不会消失
2024-09-13 20:54:17
方法一:将事件放在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>
最新文章
- linux基本知识0
- cygwin和mingw的区别
- c#中高效的excel导入sqlserver的方法
- Bmob开发指南【android端】
- boa服务器make错误
- linux下共享内存mmap和DMA(直接访问内存)的使用 【转】
- HTML4 和 HTML5 的10个关键区别
- IIS OCIEnvCreate failed with return code -1
- 机器学习&;深度学习经典资料汇总,data.gov.uk大量公开数据
- Hdu5517 Triple
- jQuery源码笔记——延迟对象
- hibernate的通配符比拼接sql到底好在哪?
- php生成html 伪静态??
- selenium 学习之路开始了,一遍搬一遍理解学习,加油!!!
- selenium的八大定位元素的方式
- 手写JavaScript常用的函数
- python 绘图pylab
- js版的in_array的实现方法
- Linux下安装Hadoop
- 利用python同步windows和linux文件
热门文章
- Extjs 实用——不定时更新
- NHibernate分页
- START167 AND BOOT167
- Could not load the assembly &#39;App_Web_cwclgcuu&#39;. Make sure that it is compiled before accessing the page.
- .cmd文件不小心管理记事本打开的恢复
- [Angular2 Form] Use RxJS Streams with Angular 2 Forms
- jQuery代码性能小细节
- SSD(固态硬盘)简介
- 程序的内存分配 C\C++
- js json与对象的相互转换