读书人

求诸位大神帮忙想破头了都没想出来

发布时间: 2013-02-28 11:33:09 作者: rapoo

求各位大神帮忙,想破头了都没想出来,跪求
这是一个点绕圆轨迹运动的程序,只是一个点,但是结果留下了哪一点的运动轨迹,程序代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 点绕圆轨迹运动
{
public partial class Form1 : Form
{
public Bitmap bit;
public Bitmap bitmap;
public Pen pen = new Pen(Color.Black,2);

double a;
double b;
double angle;
int degrees = 0;

//public Graphics de;

public Form1()
{
InitializeComponent();
Graphics de = this.CreateGraphics();
de.DrawEllipse(pen, 50, 50, 100, 100);
}


public int j=0;


private void timer1_Tick(object sender, EventArgs e)
{
angle = Math.PI * degrees / 180.0;
a = Math.Cos(angle) * 50;
b = Math.Sin(angle) * 50;
//this.Invalidate();
degrees++;
}

public Bitmap drawbitmap;
public void drawimage()
{
//drawbitmap = new Bitmap(50, 50);
//Graphics draw = Graphics.FromImage(drawbitmap);
//draw.DrawEllipse(new Pen(Color.Pink, 2), 0, 0, 50, 50);
}
public int aa = 1;
private void timer2_Tick(object sender, EventArgs e)
{
drawbitmap = new Bitmap(8, 8);

Graphics draw = Graphics.FromImage(drawbitmap);



draw.DrawEllipse(new Pen(Color.Red, 2), 0, 0, 6, 6);
Graphics ab = this.pictureBox1.CreateGraphics();
ab.DrawRectangle(new Pen(Color.Red, 3), 20 * aa, 200, 10, 10);
ab.DrawImage(drawbitmap, 20 * aa, 100);
draw.FillEllipse(Brushes.Black, 0, 0, 8, 8);

ab.DrawEllipse(pen, 2, 2, 4, 4);
ab.DrawImage(drawbitmap, 100 - 4 + (float)a, 100 - 4 + (float)b);


//ab.Clear(Color.Transparent);

aa++;

}



int i = 0;
private void button_start_Click_1(object sender, EventArgs e)
{
i++;
if (i % 2 == 1)
{
timer1.Start();
timer2.Start();
}
else if (i % 2 == 0 || j >= 10)
{
timer1.Stop();
timer2.Stop();
}
}



}
}


还有,就是怎么更新画布的一部分图,而另一部分不变呢???
[解决办法]
很简单啊,你没擦除。
绘图代码放到Paint事件中。

读书人网 >.NET

热点推荐