简体   繁体   English

Visual Studio C中的PictureBox越野车运动#

[英]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.

相关问题 在Visual Studio C#中的PictureBox中填写Function? - Fill in Function in PictureBox in Visual Studio C#? 如何使用C#将图像加载到Visual Studio中的PictureBox上 - How to Load an Image onto PictureBox in Visual Studio using C# Visual Studio 2015 C#与PictureBox的缓慢单击 - Visual Studio 2015 C# Slow Click with PictureBox 将外部图像分配给Visual Studio 2008(C#)中的Picturebox? - Assign an external image to a Picturebox in Visual Studio 2008 (C#)? 图片框控件无法正常使用C#.NET(Visual Studio) - picturebox Control is not working C# .NET (Visual Studio) 如何在边界中保持移动PictureBox C#Visual Studio 2010 - How to keep moving PictureBox in boundaries C# Visual Studio 2010 如何使用C#在Visual Studio中的图片框中访问图像的名称 - How do you access the name of the image in a picturebox in Visual Studio using C# 如何在Visual Studio中为迷宫设计项目中的C#中单击图片框? - How to make picturebox in C# clickable in visual Studio for maze design project? 如何才能逐渐且平滑地更改PictureBox的大小? (在Winforms中,C#,Visual Studio 2013) - How can I change PictureBox size incrementally and smoothly ? ( in winforms , c# , visual studio 2013 ) Visual Studio C# pictureBox - 从构造函数中绘图不显示 - Visual Studio C# pictureBox - drawing in From constructor doesn't show up
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM