gpt4 book ai didi

c# - 在 C# 中移动图像

转载 作者:行者123 更新时间:2023-11-30 16:31:32 25 4
gpt4 key购买 nike

我想将一个小图像加载到 WinForms pictureBox 控件中,然后将其动画移动到窗体的另一侧。

我已经加载图像并使用计时器移动图像,但是当我运行它时,应用程序只显示 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();
}
}
}

最佳答案

这个有用吗?抱歉,我现在无法在我所在的位置(在没有 VS 的上网本上)进行测试。

public partial class Form1 : Form
{
void timer_Tick(object sender, EventArgs e)
{
int x = pictureBox1.Location.X;
int y = pictureBox1.Location.Y;

pictureBox1.Location = new Point(x+25, y);

if (x > this.Width)
timer1.Stop();
}

public Form1()
{
InitializeComponent();

timer1.Interval = 10;
timer1.Tick += new EventHandler(timer_Tick);
}

private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Show();
timer1.Start();
}
}

关于c# - 在 C# 中移动图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4833864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com