我有一个带有PictureBox控件的Windows窗体,其中包含一个图像,我想要做的是将PictureBox控件缓慢移动到右侧。这是我的代码:
Point currentPoint = pictureBox_Logo.Location;
for (int i = 0; i < 25; i++)
{
pictureBox_Logo.Location = new Point(pictureBox_Logo.Location.X + 1, pictureBox_Logo.Location.Y);
Thread.Sleep(30);
}
这里的问题是,当执行代码而不是看到图片移动时,我看到了白色图片移动并且移动停止了图片出现。我没有什么问题,请给予帮助。
谢谢
代码:
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();
}
}
原始线程在这里Move images in C#
尝试在Thread.Sleep(30)之后使用pictureBox_Logo.Refresh();或寻找标准的计时器控件。
我的代码写得很好,但是我做错了把代码放在事件中:
private void Form1_Shown(object sender, EventArgs e);
但是当我将代码放入按钮时,它可以正常工作。