我如何“移动”图片框网格周围的图片框图片? [英] How do I "move" a picturebox image around a grid of pictureboxes?

查看:85
本文介绍了我如何“移动”图片框网格周围的图片框图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚如何使用WASD /箭头键将图像从图片框网格中的一个图片框移动到另一个图片框(所有图片框都是在二维数组中创建,对于x和y)。有没有办法我可以为每个图片框分配co
纵坐标,我可以操纵它来改变图片框中的图像以给出运动的幻觉?

I cannot figure out how to move an image from one picturebox to another inside a grid of pictureboxes (all of the pictureboxes are created in an 2 dimensional array, for x and y ) with WASD/arrow keys. Is there a way I can assign each picturebox with co ordinates where I can manipulate it to change in the image in the pictureboxes to give the illusion of movement?

例如:程序以picturebox(3,3)开头以设置播放器图像,并且变量名为"CurrentPicBox = picturebox(Xpos,Ypos)"。 ;用户按W /向上箭头;这使得图片框(具有播放器图像集)清除图像
并使"CurrentPicBox = picturebox(Xpos,Ypos + 1)"。然后使图片框(3,4)具有图像集。

For example: program starts with picturebox (3,3) to have the player image set and a variable called "CurrentPicBox = picturebox(Xpos,Ypos)" ; User presses W/Up arrow; this makes the picturebox (that has the player image set) to clear the image and makes "CurrentPicBox = picturebox(Xpos, Ypos + 1). Which then makes the picturebox(3,4) have the image set.

这是否有效或逻辑是否正确?

Would this work or is this logic incorrect?




推荐答案

以下是一个示例移动图片框。

Here is an example of moving a picturebox.

有许多方法可以做到这一点,做这种动画的最佳方法取决于所需的结果。

There are many ways to do things and the best way to do this kind of animation depends on the desired result.

所以我的下一个问题是你在整体上做了什么?国际象棋比赛?使用你描述的图片框会很快变得尴尬,并且有更好的方法来进行游戏。但是如果你只是想练习学习移动控件那么这就是你需要的

So my next question is what is it you are making overall? A chess game? Using pictureboxes as you describe will quickly become awkward and there are better ways to do a game. But if you just want to practice learning to move controls then this is what you need.

描述你想要的更多或图像或链接。

Describe more of what you want or an image or link.

PS我想你想要一个网格继续前进。我看到你只想将图像移动到图片框网格中的新图片框。

PS I guess you want a grid to move on. I see you just want to move the image to a new picturebox in a grid of pictureboxes.

所以你所描述的是一个开始。

So yes what you describe is sort of a start.

然而,还有其他方法可以做得更好。目的是什么?

However again there are other ways to do it maybe better. What is the purpose?

如果它像棋盘那样会有多少行和列。什么类型的图形?检查员?还是女王形象?等等。

If it was a like a chessboard how many rows and columns will it have. What type of graphics? A checker? Or a Queen image? etc.

你是制作世界上最好的游戏还是只是为了练习才能学到一些东西?

Are you making the worlds best game or is it just for practice to learn something?

这个例子用箭头移动一个图片框密钥。

This example moves one picture box with the arrow keys.

Public Class Form5

    Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        KeyPreview = True

    End Sub

    Private Sub Form5_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
        Select Case e.KeyCode
            Case Keys.Up
                PictureBox1.Location = New Point(PictureBox1.Location.X, PictureBox1.Location.Y - 1)
            Case Keys.Left
                PictureBox1.Location = New Point(PictureBox1.Location.X - 1, PictureBox1.Location.Y)
            Case Keys.Right
                PictureBox1.Location = New Point(PictureBox1.Location.X + 1, PictureBox1.Location.Y)
            Case Keys.Down
                PictureBox1.Location = New Point(PictureBox1.Location.X, PictureBox1.Location.Y + 1)
        End Select

        If PictureBox1.Left < 0 Then PictureBox1.Left = 0
        If PictureBox1.Left > ClientSize.Width - 1 Then PictureBox1.Left = ClientSize.Width - 1
        If PictureBox1.Top < 0 Then PictureBox1.Top = 0
        If PictureBox1.Bottom > ClientSize.Height Then PictureBox1.Top = ClientSize.Height - PictureBox1.Height
    End Sub

End Class


这篇关于我如何“移动”图片框网格周围的图片框图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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