触摸表单末尾后如何将图片框的方向向左移动 [英] How to move the direction of picturebox to left after touching the end of the form

查看:62
本文介绍了触摸表单末尾后如何将图片框的方向向左移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试像蝙蝠游戏那样开发游戏,我希望图片框向左移动,能够将其上下移动,也可以向右移动,我希望它向左移动,我使用的控件是图片框为球,标签为蝙蝠和2个计时器控件.

代码:-

Iam trying to develop at game like bal bat game,i want the picturebox to move to left,iam able to move it top to bottom and also right,i want it to move to left direction, the controls what i used are picturebox as ball,label as bat and 2 timer controls .

code :-

private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            int i = (int)e.KeyCode;
            if (i == 37 && label1.Left > 0)
                label1.Left = label1.Left - 3;
            if (i == 39 && label1.Left < this.Width - label1.Width)
                label1.Left = label1.Left + 3;
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            pictureBox1.Top = pictureBox1.Top - 5;
            if (pictureBox1.Top < 0)
            {
                timer1.Enabled = false;
                timer2.Enabled = true;
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            pictureBox1.Top = pictureBox1.Top + 5;
            pictureBox1.Left = pictureBox1.Left + 2;
            if(label1.Top == pictureBox1.Top && pictureBox1.Left > label1.Left && pictureBox1.Left < label1.Right)
            {
                timer1.Enabled = true;
                timer2.Enabled = false;
                
            }
        }

推荐答案

快速答案是:

The quick answer is:

pictureBox1.Left -= 2;



真正的答案是,这完全是错误的动画制作方法.您想使用Paint事件处理程序中的Graphics类或OnPaint替代来绘制图像.

尼克



The real answer is that this is completely the wrong way to do animation. You want to draw your images using the Graphics class in a Paint event handler or OnPaint override.

Nick


这篇关于触摸表单末尾后如何将图片框的方向向左移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆