当前位置:编程学习 > C#/ASP.NET >>

急!在pictureBox中绘图

最近写了一个在PicturesBox中绘图的程序,就是无法显示,请大侠指点!代码如下:
 private void MidHGLLMDesign_Paint(object sender, PaintEventArgs e)
        {
            if (bmp != null)    //bmp是一个位图变量 
            {
                Graphics gl = Graphics.FromImage(bmp);
                gl.Clear(Color.White);
                System.Drawing.Point pt1 = new System.Drawing.Point(pictureBox2.Location.X + 3, pictureBox2.Location.Y - 3);
                System.Drawing.Point pt2 = new System.Drawing.Point(pt1.X +200, pt1.Y+200);
                SolidBrush br = new SolidBrush(Color.Red);
                gl.DrawLine(new Pen(br, 2), pt1, pt2);
                Bitmap Oldbmp = bmp;
                pictureBox2.Image = Oldbmp;
                bmp = null;
            }
        }
谢谢!急!
--------------------编程问答--------------------  System.Drawing.Point pt1 = new System.Drawing.Point(pictureBox2.Location.X + 3, pictureBox2.Location.Y - 3);

这句话不对,找坐标点错了

直接换成
 System.Drawing.Point pt1 = new System.Drawing.Point( 3, 3);
吧 --------------------编程问答-------------------- ...... --------------------编程问答-------------------- 顶帖!不懂
--------------------编程问答--------------------  private void MidHGLLMDesign_Paint(object sender, PaintEventArgs e)
  {
  if (bmp != null) //bmp是一个位图变量  
  {
  Graphics gl = Graphics.FromImage(bmp);
  gl.Clear(Color.White);
  System.Drawing.Point pt1 = new System.Drawing.Point(pictureBox2.Location.X + 3, pictureBox2.Location.Y - 3);
  System.Drawing.Point pt2 = new System.Drawing.Point(pt1.X +200, pt1.Y+200);
  SolidBrush br = new SolidBrush(Color.Red);
  gl.DrawLine(new Pen(br, 2), pt1, pt2);
  Bitmap Oldbmp = bmp;
  pictureBox2.Image = Oldbmp;
  
//下面这句不要,你设为null后就没图像了
//bmp = null;
  }
  }
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,