Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Graphics vs pictureBox

$
0
0

Hello there. I added two pictureBoxes on my Windows Form. I filled both pictureBoxes with images. I tried to made like pictureBox1 to move. And so I did. But there is a problem. When the pictureBox1 is moving, it seems like it's moving hardly... Like it has ping ^^.

Here is my code:

private void Form2_KeyPress(object sender, KeyPressEventArgs e) { switch (e.KeyChar) { case 'w': case 'W': pictureBox1.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y - 2); break; case 's': case 'S': pictureBox1.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y + 2); break; case 'a': case 'A': pictureBox1.Location = new Point(pictureBox1.Location.X - 2, pictureBox1.Location.Y); break; case 'd': case 'D': pictureBox1.Location = new Point(pictureBox1.Location.X + 2, pictureBox1.Location.Y); break; }

            Rectangle myRect = new Rectangle(pictureBox1.Location.X, pictureBox1.Location.Y, pictureBox1.Width, pictureBox1.Height);
            Rectangle mySecondRect = new Rectangle(pictureBox2.Location.X, pictureBox2.Location.Y, pictureBox2.Width, pictureBox2.Height);
            if (myRect.IntersectsWith(mySecondRect))
            {
                MessageBox.Show("Congruatiulations!");
            }

}


Is there any other possibility to move an image? To load the image like a graphic and to move that graphic?





Viewing all articles
Browse latest Browse all 12583

Trending Articles