-6

我正在制作一个程序,我试图让球遵循寓言曲线。

我编写了一些代码,其中计时器是变量“a”的值。

public partial class Form1 : Form
{
    Class1 class1;
    Class2 class2 = new Class2();

    public Form1()
    {
        Class1 =new Class1(15,a);
        InitializeComponent();

    }

    public int a = 0;

    private void Timer1_Tick(object sender, EventArgs e)
    {
        a += 1
    }
 }

第一类:

class Class1     
{
    private   int radie;
    private   int x;

    public Boll(int p, int c)
    {
        this.radie = p;
        this.x = c;
    }

    public void Rita(Graphics g)
    {
        SolidBrush Brush = new SolidBrush(Color.White);
        g.FillEllipse(Brush, x, 100, radie, radie);
    }
}

第 2 类并不重要,因为问题出在第 1 类中,我希望变量“x”与计时器一起更新。现在“x”只在我开始调试时获取计时器的值。我想要图形,在这种情况下,每次“x”的值发生变化时,球都会更新(或类似的)

4

1 回答 1

0

在类 1 中创建一个这样的方法

public void Update()
{
// Put logic here to update position for your ball on the curve.
}

当您增加时间时,从类 2 调用更新。

private void Timer1_Tick(object sender, EventArgs e)
{
    Class1.Update();
    a += 1
}
于 2013-05-30T15:19:37.393 回答