需要一個button,一個timer
public partial class Form1 : Form
{
int x, y, a = 0, b = 0, c = 0, d = 0;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
button1.Text = "";
}
private void timer1_Tick(object sender, EventArgs e)
{
x = a;
if (a >= 650) b = 1;
if (a <= 0) b = 0;
if (b == 1)
{
a = a - 50;
}
else
{
a = a + 50;
}
y = c;
if (c >= 300) d = 1;
if (c <= 0) d = 0;
if (d == 1)
{
c = c - 50;
}
else
{
c = c + 50;
}
button1.Location = new Point(x, y);
}
}
沒有留言:
張貼留言