我想翻一个图片框。 [英] I want to flip a picture box.

查看:107
本文介绍了我想翻一个图片框。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



首先,我是初学者急剧编码。



我有一个图片框和一个计时器(启用,间隔= 25)。



我在图片框中插入了一张鸟的gif图像。



在我写过的Timer事件中,



Hello guys,

First of all iam a beginner c sharp coding.

I have a picturebox and a timer(enabled, interval = 25).

I have inserted a gif image of a bird in the picturebox.

And in the Timer event i have written,

bool positionBird = true;

private void timer1_Tick(object sender, EventArgs e)
        {
            if (PictureBox1.Location.X == Screen.PrimaryScreen.Bounds.Width)
            {
                positionBird = false;
            }
            else if (PictureBox1.Location.X == 0)
            {
                positionBird = true;
            }

            if(positionBird)
            {
                PictureBox1.Left += 1;
            }
            else
            {
                PictureBox1.Left += -1;
            }
        }





但我想要实现的是,当图片框触及右边界时条件变得虚假,我想在图片框中翻转鸟的图像。现在这只鸟正在做迈克尔·杰克逊的月球漫步(哈哈...... !!)。



我试图用下面的代码翻转鸟(镜子)翻转。 br $>




But what i want to achieve is, when the picture box touches the right boundary and condition become false, i want to flip the image of bird in the picturebox. Right now the bird is doing michael jackson's Moonwalk (lol..!!).

I tried to flip the flip the bird(mirror) using the below code.

else
            {
                PictureBox pict = new PictureBox();
                pict = PictureBox1;
                pict.Image.RotateFlip(RotateFlipType.RotateNoneFlipX);
                PictureBox1.Left += -1;
            }





但它看起来很奇怪,它显示了翻转图像和正常图像。有人可以帮我这个。正如我已经告诉我一个初学者一些简单的代码和解释将非常有帮助。还有人可以告诉我我做错了什么。



But it looks weird, it shows the flip image and normal image both. Can someone help me on this. As i already told iam a beginner some simple code with explanation will be very much helpful. also can someone tell me what iam doing wrong.

推荐答案

好的,有几件事。

首先,请不要使用主屏幕宽度 - 您无法在表单外显示PictureBox,因此请改用表单宽度。

其次,不要寻找完全匹配 - 检查大于或等于代替。当你增加1时,你的方式可以正常工作,但是如果你决定改变速度,它很容易就会失败。



然后,把它转过来你就是这样,非常接近:你需要做的就是稍微改变你的代码,然后移动它:



Ok, a couple of things.
First off, don't use the primary screen width - you can't show your PictureBox outside your Form, so use the form width instead.
Secondly, don't look for an exact match - check for "greater than or equal to" instead. Your way works fine when you increment by one, but if you decide to vary the speed, it could easily fail.

Then, to turn it round you are very, very close: all you need to do, is change your code very slightly, and move it around:

private void timer1_Tick(object sender, EventArgs e)
    {
    if (pictureBox1.Location.X >= Width)
        {
        pictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipX);
        positionBird = false;
        }
    else if (pictureBox1.Location.X + pictureBox1.Width <= 0)
        {
        pictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipX);
        positionBird = true;
        }

    if (positionBird)
        {
        pictureBox1.Left += 10;
        }
    else
        {
        pictureBox1.Left += -10;
        }
    }

(顺便说一句:我移动左侧检查,因此当图片不可见时图片会翻转)

(BTW: I moved the left hand side check, so the picture swaps over when it isn't visible)


这篇关于我想翻一个图片框。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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