rightT is a timer which is supposed to change the image of the object (which inherits
from PictureBox
) when the code runs (after I turned on the timer) the image changes only once and never changes again anyone knows why it happens?
rightT是一个计时器,它应该在代码运行时(在我打开计时器之后)改变对象的图像(继承自PictureBox),图像只改变一次并且永远不会再改变,任何人都知道它为什么会发生?
rightT.Tick += (EventHandler)delegate
{
this.Location = new Point(this.Location.X + _movementSize,
this.Location.Y); // moves the character
this.Image = this.rightState++ % 2 == 0 ? Properties.Resources.MarioAnimation2 : Properties.Resources.MarioAnimation1; // changes the photo
this.Refresh();
};
2 个解决方案
#1
-1
You can use :
您可以使用 :
this.Update();
insted of
绝对的
this.Refresh()
Actually I don't know the difference between Update and Invalidate but you can try both of them.
实际上我不知道Update和Invalidate之间的区别,但您可以尝试这两者。
#2
-1
I think Application.DoEvents(); is better suited for forcing the gui to update. you can place it anywhere you like and as much as you like.
我认为Application.DoEvents();更适合强迫gui更新。你可以把它放在任何你喜欢的地方,也可以随意放置。
#1
-1
You can use :
您可以使用 :
this.Update();
insted of
绝对的
this.Refresh()
Actually I don't know the difference between Update and Invalidate but you can try both of them.
实际上我不知道Update和Invalidate之间的区别,但您可以尝试这两者。
#2
-1
I think Application.DoEvents(); is better suited for forcing the gui to update. you can place it anywhere you like and as much as you like.
我认为Application.DoEvents();更适合强迫gui更新。你可以把它放在任何你喜欢的地方,也可以随意放置。