请问:怎样在Paint以外的函数画线?
我在其它函数里定义不了PaintEventArgs e,画不了线!应该怎么做才画得了?大家帮帮忙!
using System.Drawing; private void button1_Click(object sender, EventArgs e) { Graphics g = CreateGraphics(); Pen pen = new Pen(Color.Red, 1); g.DrawLine(pen, 50,50,100,100); pen.Dispose(); g.Dispose(); }
Graphics g = CreateGraphics();//System.Drawing.Graphics g = this.CreateGraphics(); g.Clear(Color.White);
Bitmap bmp = new Bitmap("1.bmp"); PixelFormat format = bmp.PixelFormat; RectangleF cloneRect = new RectangleF(50, 50, 10, 10);// 取图片的一块 Bitmap pic = bmp.Clone(cloneRect, format); Graphics g = CreateGraphics(); g.DrawImage(pic, 50, 50, pic.Width, pic.Height,GraphicsUnit.Pixel, null); // 在50,50的位置上贴 pic,注意最后一个属性为 ImageAttributes 对象的透明色,也就是 pic 的透明度