[英]PictureBox buggy movement in Visual Studio C#
Problem 问题
I have PictureBoxes and I want them to move. 我有PictureBoxes,我希望它们移动。 I make them move using a timer.
我让他们使用计时器移动。 I can get them to move, but every time they move a pixel they leave a white background at their previous position.
我可以让它们移动,但每次移动像素时,它们都会在之前的位置留下白色背景。 And when moving they make my TextBoxes blink.
移动时,他们让我的TextBoxes闪烁。
This is how it looks: https://gyazo.com/cdd17b0e88a86b4dec115ceff41b44c5 这是它的外观: https : //gyazo.com/cdd17b0e88a86b4dec115ceff41b44c5
Please don't pay much attention on my poor Paint skills 请不要太注意我糟糕的油漆技巧
Code 码
public partial class Form1 : Form
{
int timeTicker;
int timeMin;
int timeSec;
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
timeTicker++;
Timer(timeTicker);
//playerPics is a PictureBox array that has all the images stored
TopMovement(playerPics[0],timeTicker);
}
private void Timer(int secs)
{
timeSec = secs;
if(secs == 60)
{
timeMin += 1;
timeTicker = 0;
}
tbxTimer.Text = "Time: " + timeMin + ":" + timeSec;
}
private void TopMovment(PictureBox top, int time)
{
int y = (int)(time * 1.7);
int x = (int)(time * 0.3);
if (time < 22 && timeMin < 1)
{
top.Top -= y;
top.Left += x;
}
}
}
Try putting DoubleBuffered = true;
尝试将
DoubleBuffered = true;
in your constructor. 在你的构造函数中。 Also, a timer is never a good way to move graphics.
此外,计时器永远不是移动图形的好方法。 It will always skip a tick and isn't really useful for what you're trying to do.
它总是会跳过一个勾号,对你正在尝试做的事情并没有什么用处。 I wrote this a while ago, check it out.
我刚才写了这个,看看吧。 It's not perfect but a lot better than using a timer.
它不是完美的,但比使用计时器要好得多。 http://pastebin.com/9P77eaAU
http://pastebin.com/9P77eaAU
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.