0

我有一个带有包含图像的 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);
        }

这里的问题是,当代码执行而不是看到图片移动时,我看到一个白色的图片移动并且移动停止,直到图片出现。

我错过了什么,我能做些什么?

4

3 回答 3

1

代码:

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#

于 2012-09-13T08:23:12.133 回答
0

我的代码写得很好,但我做错的是把代码放在一个事件中:

private void Form1_Shown(object sender, EventArgs e);

但是当我将我的代码放在一个按钮中时,它可以正常工作。

于 2012-09-13T08:27:45.283 回答
0

尝试在 Thread.Sleep(30) 之后使用 pictureBox_Logo.Refresh(); 或者寻找标准的定时器控件。

于 2012-09-13T08:21:50.293 回答