我想将一个小图像加载到WinForms pictureBox
控件中,然后将它移动到移动到窗体的另一侧。在C#中移动图像
我已经加载图像,并使用计时器来移动图像,但是当我运行它时,应用程序只显示pictureBox
及其图像的最终位置。
我如何才能平滑过渡到最终位置?
这里是我到目前为止的代码:
public partial class Form1 : Form
{
private int counter = 0;
void timer_Tick(object sender, EventArgs e)
{
counter++;
if (counter == 1)
{
pictureBox1.Show();
timer1.Stop();
counter = 0;
}
}
public Form1()
{
InitializeComponent();
timer1.Interval = 10;
timer1.Tick += new EventHandler(timer_Tick);
}
private void button1_Click(object sender, EventArgs e)
{
while(i<=100){
int x = pictureBox1.Location.X;
int y = pictureBox1.Location.Y;
pictureBox1.Location = new Point(x+25, y);
timer1.Start();
}
}
}
'while(i <= 100){'Where is'i' defined?根据所提供的代码,您的循环永远不会终止。 – Amy