我想实现在form中移动一个圆(用picturebox画的圆)(graphic),在移动过程中留下圆的轨迹,基本的过程我已写完,不知怎么写轨迹。
我的想法是在form上画出圆,但是不行。相关代码:PaintEventArgs pain = null;private new void Paint(PaintEventArgs e)
        {
            Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            Graphics g = Graphics.FromImage(bmp);
            SolidBrush b = new SolidBrush(Color.White);
            Pen p = new Pen(b, 1);
            g.DrawArc(p, 0, 0, pictureBox1.Width - 1, pictureBox1.Height - 1, 0, 360);
            g.FillEllipse(b, e.ClipRectangle);
            e.Graphics.DrawImage(bmp, new Point(pictureBox1.Location.X, pictureBox1.Location.Y));
            pain = e;
        }//这是画轨迹的函数 private void timer5_Tick(object sender, EventArgs e)
        {
            Paint(pain);
        }//这是用来调用画轨迹的timer不知怎么,在运行过程中(开始启动时)报错在
g.FillEllipse(b, e.ClipRectangle);
e.Graphics.DrawImage(bmp, new Point(pictureBox1.Location.X, pictureBox1.Location.Y));
两行。
不知哪里错了,希望大家帮帮忙,也希望有好解决方法的高手指点。
在线等。。

解决方案 »

  1.   

    在控件中进行内容描绘总体来说有以下几种方法:1.重载OnPaint方法.
    2.添加Paint事件.
    3.直接调用this.CreateGraphics方法进行描绘.(不推荐.)lz,按你的思路,图像根本不会出现在控件上.
      

  2.   

    轨迹?
    是想要画面上有这样的效果吗?oooooooooo一堆圆?
      

  3.   

     Paint(pain);
    这个有问题吧,应该refresh什么的
      

  4.   

    你传个null参数给paint?能运行才怪
      

  5.   

    嗯嗯Refresh();
    然后把paint改成onpaint
      

  6.   

    我那是初始化pain,是pain = null,不是paint
    refresh();没用,我试了
      

  7.   

    refresh调用的是onpaint,你那个是paint
      

  8.   


    不是改进的问题....你思路完全错了.
    搞清楚要在哪里画先.你当前程序中获取到的Graphics在实际应用中根本不存在,你怎么画?