我想实现在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));
两行。
不知哪里错了,希望大家帮帮忙,也希望有好解决方法的高手指点。
在线等。。
我的想法是在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));
两行。
不知哪里错了,希望大家帮帮忙,也希望有好解决方法的高手指点。
在线等。。
2.添加Paint事件.
3.直接调用this.CreateGraphics方法进行描绘.(不推荐.)lz,按你的思路,图像根本不会出现在控件上.
是想要画面上有这样的效果吗?oooooooooo一堆圆?
这个有问题吧,应该refresh什么的
然后把paint改成onpaint
refresh();没用,我试了
不是改进的问题....你思路完全错了.
搞清楚要在哪里画先.你当前程序中获取到的Graphics在实际应用中根本不存在,你怎么画?