Count ++ when collision between two pictureboxes plus random drop of pictureBox - c#

I coding a very simple program.
A pictureBox drops from above and another pictureBox (located at button) have to grab the pictureBox (collision between those two picturesBoxes) and then you get one point.
My issue is when the collision happens then Point are counting up as long the collision between the two pictureBoxes happens.
How to stop this and only count ++ when a collision happens?
- I'm total rookie coding c# so please don't answer a very advanced answer :)
namespace Animation
{
public partial class Form1 : Form
{
Point p1 = new Point();
Point p2 = new Point();
int bredde;
int højde;
int score;
int count = 0;
public Form1()
{
InitializeComponent();
p1.X = pictureBox1.Location.X;
p1.Y = pictureBox1.Location.Y;
p2.X = pictureBox2.Location.X;
p2.Y = pictureBox2.Location.Y;
højde = ClientSize.Height;
bredde = ClientSize.Width;
}
Boolean max = true;
void collision()
{
if (pictureBox1.Bounds.IntersectsWith(pictureBox2.Bounds))
{
score++;
label1.Text = Convert.ToString(score);
max = true;
}
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.W && p1.Y > 0)
p1.Y -= 3;
if (e.KeyData == Keys.D && p1.X + pictureBox1.Width < bredde)
p1.X +=3;
if (e.KeyData == Keys.A && p1.X > 0)
p1.X -=3;
if (e.KeyData == Keys.S && p1.Y + pictureBox1.Height < højde)
p1.Y +=3;
pictureBox1.Location = p1;
if (e.KeyData == Keys.W && p2.Y > 0)
if (e.KeyData == Keys.D && p2.X + pictureBox2.Width < bredde)
if (e.KeyData == Keys.A && p2.X > 0)
if (e.KeyData == Keys.S && p2.Y + pictureBox2.Height < højde)
pictureBox2.Location = p2;
}
private void timer1_Tick(object sender, EventArgs e)
{
collision();
p2.Y +=5;
pictureBox2.Location = p2;
}
private void buttonStart_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void buttonStop_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
}
}
}

Related

hold longer will jump higher (C# winforms)

I am trying to make a 2D game in winforms. i want my character to be able to double jump and if i hold the space key (jump) for a long time i will jump higher or if i hold the space key (jump) less i will jump lower (Note that although holding longer will jump higher, but only up to a fixed level, not to infinity). but I can only double jump and only jump 1 fixed distance, not hold the space longer to jump higher or hold it shorter to jump lower, someone help me, below is my code.
public partial class GamePlay_Page : Form
{
bool goRight, goLeft;
int gravity = 16;
int force;
bool jump;
int jumpTimes = 2;
public GamePlay_Page()
{
InitializeComponent();
}
private void GamePlay_Page_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.D)
{
goRight = true;
Trex.Image = Properties.Resources.running;
}
if (e.KeyCode == Keys.A)
{
goLeft = true;
Trex.Image = Properties.Resources.running2;
}
if (e.KeyCode == Keys.W && jumpTimes > 0)
{
jump = true;
force = gravity;
jumpTimes -= 1;
}
private void gameT(object sender, EventArgs e)
{
if (goRight == true && Trex.Right < 600)
{
Trex.Left += 5;
}
if (goLeft == true && Trex.Left > 10)
{
Trex.Left -= 5;
}
if (jump == true)
{
Trex.Top -= force;
force -= 1;
}
if (Trex.Top + Trex.Height >= backgroundAbove.Height)
{
Trex.Top = backgroundAbove.Height - Trex.Height;
}
else
{
Trex.Top += 3;
}
if (Trex.Top + Trex.Height == backgroundAbove.Height)
{
jumpTimes = 2;
}
private void GamePlay_Page_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.D) { goRight = false; }
if (e.KeyCode == Keys.A) { goLeft = false; }
}
I am not sure if this is what you mean, and change it according to your needs.
Please see my example:
Add a stopwatch to judge the length of the pressing time, in order to prevent the intensity from bursting.
What I set is to give a fixed force for pressing more than 3s, otherwise give an initial force for gravity.
Change it according to your needs.
You can completely change it to a force multiplied by time.
Stopwatch watch =new Stopwatch();
watch.Start();//start the timer
watch.Stop(); //stop the timer
watch.ElapsedMilliseconds// Show duration in milliseconds(Type is long)
watch.Reset();//reset the timer
Put the timing start into the KeyDown event:
if (e.KeyCode == Keys.W && jumpTimes > 0)
{
//jump = true;
//force = gravity;
//jumpTimes -= 1;
watch.Start();
}
Put the timing end and trigger the jump into the KeyUp event:
if (e.KeyCode == Keys.W && jumpTimes > 0)
{
watch.Stop();
jump = true;
jumpTimes -= 1;
if (watch.ElapsedMilliseconds > 300)//>3s
{
force = 30;
}
else
{
force = gravity;
}
}
watch.Reset();
All the codes:
using System;
using System.Diagnostics;
using System.Windows.Forms;
namespace GamePlay_Page {
public partial class GamePlay_Page : Form {
public GamePlay_Page () {
InitializeComponent();
}
bool goRight, goLeft;
int gravity = 16;
int force;
bool jump;
int jumpTimes = 2;
Stopwatch watch =new Stopwatch();
private void GamePlay_Page_Load (object sender, EventArgs e) {
}
private void GamePlay_Page_KeyDown (object sender, KeyEventArgs e) {
if (e.KeyCode == Keys.D)
{
goRight = true;
Trex.Image = Properties.Resources.ch;
}
if (e.KeyCode == Keys.A)
{
goLeft = true;
Trex.Image = Properties.Resources.ca;
}
if (e.KeyCode == Keys.W && jumpTimes > 0)
{
//jump = true;
//force = gravity;
//jumpTimes -= 1;
watch.Start();
}
}
private void GamePlay_Page_KeyUp (object sender, KeyEventArgs e) {
if (e.KeyCode == Keys.W && jumpTimes > 0)
{
watch.Stop();
if (e.KeyCode == Keys.W && jumpTimes > 0)
{
watch.Stop();
jump = true;
jumpTimes -= 1;
if (watch.ElapsedMilliseconds > 300)//>3s
{
force = 30;
}
else
{
force = gravity;
}
}
}
watch.Reset();
if (e.KeyCode == Keys.D)
{
goRight = false;
}
if (e.KeyCode == Keys.A)
{
goLeft = false;
}
}
private void Timer1_Tick (object sender, EventArgs e) {
if (goRight == true && Trex.Right < 600)
{
Trex.Left += 5;
}
if (goLeft == true && Trex.Left > 10)
{
Trex.Left -= 5;
}
if (jump == true)
{
Trex.Top -= force;
force -= 1;
}
if (Trex.Top + Trex.Height >= backgroundAbove.Height)
{
Trex.Top = backgroundAbove.Height - Trex.Height;
}
else
{
Trex.Top += 3;
}
if (Trex.Top + Trex.Height == backgroundAbove.Height)
{
jumpTimes = 2;
}
G.Text = gravity.ToString();
F.Text = force.ToString();
T.Text = Trex.Top.ToString();
L.Text = Trex.Left.ToString();
J.Text = jumpTimes.ToString();
W.Text = watch.ElapsedMilliseconds.ToString();
}
}
}
main page:
Output:
If you have questions about my code, please comment below and I will follow up as soon as possible.

Change a back color that exists in a different form

Hello I'm trying to change a square color pnlPlayer in PlayingField.cs however the choice must exist on ColorChoice.cs
Whenever I try to change the pnlPlayer.BackColor to a different color the pnlPlayer tells me it does not exist in the current context.
how can I change the backColor of pnlPlayer that exists in PlayingField from ColorChoice
Here is the relevant code.
ColorChoice.cs
private void ColorChoice_Load(object sender, EventArgs e)
{
//set colors to combobox
//ComboBox ColorComboBox = new ComboBox();
ColorComboBox.Items.Add("Red");
ColorComboBox.Items.Add("Blue");
ColorComboBox.Items.Add("Green");
ColorComboBox.Items.Add("Black");
//add to combobox form
this.Controls.Add(ColorComboBox);
}
public void ColorConfirm_Click(object sender, EventArgs e)
{
PlayingField PF = new PlayingField();
PF.Show();
switch (ColorComboBox.SelectedIndex)
{
case 1:
pnlPlayer.BackColor = Color.Red; //The problems are here
break;
case 2:
pnlPlayer.BackColor = Color.Blue; //The problems are here
break;
case 3:
pnlPlayer.BackColor = Color.Green; //The problems are here
break;
case 4:
pnlPlayer.BackColor = Color.Black; //The problems are here
break;
}
PlayingField.cs
public PlayingField()
{
InitializeComponent();
StartGame();
}
public void StartGame()
{
pnlPlayer.Location = new Point(200, 200);
}
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.J || e.KeyCode == Keys.Left) //LEFT
{
int newX = (pnlPlayer.Location.X - 10 >= 0) ? pnlPlayer.Location.X - 10 : 0;
pnlPlayer.Location = new Point(newX, pnlPlayer.Location.Y);
}
else if (e.KeyCode == Keys.I || e.KeyCode == Keys.Up) //UP
{
int newY = (pnlPlayer.Location.Y - 10 >= 0) ? pnlPlayer.Location.Y - 10 : 0;
pnlPlayer.Location = new Point(pnlPlayer.Location.X, newY);
}
else if (e.KeyCode == Keys.L || e.KeyCode == Keys.Right) //RIGHT
{
int newX = (pnlPlayer.Location.X + 10 <= 400) ? pnlPlayer.Location.X + 10 : 400;
pnlPlayer.Location = new Point(newX, pnlPlayer.Location.Y);
}
else if (e.KeyCode == Keys.K || e.KeyCode == Keys.Down) //DOWN
{
int newY = (pnlPlayer.Location.Y + 10 <= 400) ? pnlPlayer.Location.Y + 10 : 400;
pnlPlayer.Location = new Point(pnlPlayer.Location.X, newY);
}
else return; //user pressed a key that does not have a function in the program
}

How to draw a Rectangle in any direction after MouseDown using C#?

How can I draw a rectangle in all directions? Current code:
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
// Starting point of the selection:
if (e.Button == MouseButtons.Left)
{
_selecting = true;
_selection = new Rectangle(new Point(e.X, e.Y), new Size());
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
// Update the actual size of the selection:
if (_selecting)
{
_selection.Width = e.X - _selection.X;
_selection.Height = e.Y - _selection.Y;
pictureBox1.Refresh(); // redraw picturebox
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && _selecting)
{
_selecting = false;
}
}
This allows me to MouseDown and then draw down and to the right, but I am unable to draw in any other direction beyond the anchor point. How can I draw a rectangle in any direction like e.g. Microsoft Paint?
I first tried:
_selection.Width = Math.Abs(e.X - _selection.X);
_selection.Height = Math.Abs(e.Y - _selection.Y);
But this creates a funny mirror effect (which is not what I want). I then tried a simple shift:
_selection.X = _selection.Left - 5;
This did what I expected and moved a static rectangle 5 units left, so I thought it would be a simple matter of continuously shifting the anchor point during the Paint event:
private void UpdateRectange(Point newPos)
{
var width = newPos.X - _selection.X;
var height = newPos.Y - _selection.Y;
_selection.Width = Math.Abs(width);
_selection.Height = Math.Abs(height);
if (width < 0 && height > 0) // move down (+) and left (-)
{
//_selection.X = _selection.Left + width;
_selection.Offset(width, 0);
}
uxScreenGrab.Refresh(); // redraw picturebox
}
But this resulted in pushing a vertical line across the screen towards the left, when moving to the left of the original anchor point.The width does not properly update for some reason.
Here's another snippet to draw a selection rectangle on a PictureBox:
//...
private Point startPoint;
private Point endPoint;
private readonly Pen P1 = new Pen(Color.SteelBlue, 2) {
Alignment = PenAlignment.Center, DashStyle = DashStyle.Dash};
//...
Set the startPoint in the MouseDown event and reset the endPoint variables:
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
startPoint = new Point(e.X, e.Y);
endPoint = Point.Empty;
}
}
Set the endPoint and call Invalidate() method in the MouseMove event:
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
var p = new Point(e.X, e.Y);
if (e.Button == MouseButtons.Left &&
!p.Equals(startPoint))
{
endPoint = p;
pictureBox1.Invalidate();
}
}
Also call Invalidate() in the MouseUp event to remove the selection rectangle:
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
pictureBox1.Invalidate();
}
Draw the selection rectangle:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
if(MouseButtons == MouseButtons.Left &&
!startPoint.Equals(endPoint) &&
!endPoint.Equals(Point.Empty))
{
var g = e.Graphics;
var rect = Rectangle.Empty;
if(startPoint.X < endPoint.X)
{
rect.X = startPoint.X;
rect.Width = endPoint.X - startPoint.X;
}
else
{
rect.X = endPoint.X;
rect.Width = startPoint.X - endPoint.X;
}
if(startPoint.Y < endPoint.Y)
{
rect.Y = startPoint.Y;
rect.Height = endPoint.Y - startPoint.Y;
}
else
{
rect.Y = endPoint.Y;
rect.Height = startPoint.Y - endPoint.Y;
}
g.DrawRectangle(P1, rect);
}
}
And don't forget to clean up:
private void YourForm_FormClosing(object sender, FormClosingEventArgs e)
{
P1.Dispose();
}
Keep it simple.
Related Posts
How to call a method that uses PaintEventArgs and coordinates variables
The solution proposed in the question looks good:
_selection.Width = Math.Abs(e.X - initiallySelectedX);
_selection.Height = Math.Abs(e.Y - initiallySelectedY);
...but You have to move the origin of the rectangle when (e.X - initiallySelectedX) < 0
So probably You want to add something like this to Your code:
var diffX = e.x - initiallySelectedX;
if (diffX < 0) _selection.X = initiallySelectedX - diffX;
var diffY = e.y - initiallySelectedY;
if (diffY < 0) _selection.Y = initiallySelectedY - diffY;
Where initiallySelectedX and initiallySelectedY are variables set onMouseDown.
this is only a rough idea.
The idea behind is that the Width and Height of the Rectangle cannot be NEGATIVE !!
UPDATE:
Keeping track of the starting point on the MouseDown event allows the anchor point to correctly update:
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
// Starting point of the selection:
if (e.Button == MouseButtons.Left)
{
_selecting = true;
_selection = new Rectangle(new Point(e.X, e.Y), new Size());
_startingPoint = e.Location;
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
// Update the actual size of the selection:
if (_selecting)
{
UpdateRectange(e.Location);
}
}
private void UpdateRectange(Point newPos)
{
var diffX = newPos.X - _startingPoint.X;
var diffY = newPos.Y - _startingPoint.Y;
var newSize = new Size(Math.Abs(diffX), Math.Abs(diffY));
if (diffX > 0 && diffY > 0)
{
_selection = new Rectangle(_startingPoint, newSize);
}
else if (diffX < 0 && diffY < 0)
{
_selection = new Rectangle(newPos, newSize);
}
else if (diffX > 0 && diffY < 0)
{
_selection = new Rectangle(new Point(_startingPoint.X, _startingPoint.Y + diffY), newSize);
}
else
{
_selection = new Rectangle(new Point(_startingPoint.X + diffX, _startingPoint.Y), newSize);
}
uxScreenGrab.Invalidate();
}
UPDATE 2:
Re-wrote UpdateRectangle to simply move the anchor point, instead of instantiating at every call:
private void UpdateRectange(Point newPos)
{
var diffX = newPos.X - _startingPoint.X;
var diffY = newPos.Y - _startingPoint.Y;
var newSize = new Size(Math.Abs(diffX), Math.Abs(diffY));
if (diffX > 0 && diffY > 0)
{
_selection.Size = newSize;
}
else if (diffX < 0 && diffY < 0)
{
_selection.Location = newPos;
_selection.Size = newSize;
}
else if (diffX > 0 && diffY < 0)
{
_selection.Y = _startingPoint.Y + diffY;
_selection.Size = newSize;
}
else
{
_selection.X = _startingPoint.X + diffX;
_selection.Size = newSize;
}
uxScreenGrab.Invalidate();
}

Pac Man cross obstacles

I'm doing a Pac-Man game on c# , and pac man cross every obstacles that I pass.
This is the entire code of my Pac-Man game:
using System;
using System.Media;
using System.Windows.Forms;
namespace Pac_Man {
public partial class Form1 : Form
{
Variables:
bool goLeft;
bool goRight;
bool goUp;
bool goDown;
int score = 0;
int totalCoins = 160;
int playerSpeed = 4;
int ghost1 = 4;
int ghost2 = 4;
Initializing:
public Form1()
{
InitializeComponent();
lblGame.Visible = false;
playSound();
}
Play sound:
private void playSound()
{
SoundPlayer simpleSound = new SoundPlayer(#"C:\Users\rsss-\OneDrive\Documentos\Visual Studio 2019\Projects\Pac_Man\Pac_Man\Sound\pacman_beginning.wav");
simpleSound.PlayLooping();
}
Key is down:
private void keyisdown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Up)
{
goUp = true;
}
if (e.KeyCode == Keys.Down)
{
goDown = true;
}
if (e.KeyCode == Keys.Left)
{
goLeft = true;
}
if (e.KeyCode == Keys.Right)
{
goRight = true;
}
}
Key is up:
private void keyisup(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Up)
{
goUp = false;
}
if (e.KeyCode == Keys.Down)
{
goDown = false;
}
if (e.KeyCode == Keys.Left)
{
goLeft = false;
}
if (e.KeyCode == Keys.Right)
{
goRight = false;
}
}
Timer:
private void timer1_Tick(object sender, EventArgs e)
{
int movement = playerSpeed;
if (goLeft)
{
foreach (Control x in this.Controls)
{
if (x is PictureBox && x.Tag == "obstacle" && x.Left == player.Left - playerSpeed && x.Top == player.Top)
{
movement = 0;
break;
}
}
player.Left -= movement;
movement = playerSpeed;
}
else if (goRight)
{
foreach (Control x in this.Controls)
{
if (x is PictureBox && x.Tag == "obstacle" && x.Left == player.Left + playerSpeed && x.Top == player.Top)
{
movement = 0;
break;
}
}
player.Left += movement;
movement = playerSpeed;
}
else if (goUp)
{
foreach (Control x in this.Controls)
{
if (x is PictureBox && x.Tag == "obstacle" && x.Top == player.Top - playerSpeed && x.Left == player.Left)
{
movement = 0;
break;
}
}
player.Top -= movement;
movement = playerSpeed;
}
else if (goDown)
{
foreach (Control x in this.Controls)
{
if (x is PictureBox && x.Tag == "obstacle" && x.Top == player.Top + playerSpeed && x.Left== player.Left)
{
movement = 0;
break;
}
}
player.Top += movement;
movement = playerSpeed;
}
if (player.Left > 641)
{
player.Left = 82;
}
else if (player.Left < 82)
{
player.Left = 641;
}
foreach (Control x in this.Controls)
{
if (x is PictureBox && x.Tag == "ghost")
{
if (((PictureBox)x).Bounds.IntersectsWith(player.Bounds))
{
gameOver();
MessageBox.Show("You Lost!" + "\n" + "Your score is " + score);
this.Close();
}
}
}
Ghosts Movement:
redGhost.Left += ghost1;
orangeGhost.Left += ghost2;
blueGhost.Left -= ghost1;
pinkGhost.Left -= ghost2;
foreach (Control c in this.Controls)
{
if (c is PictureBox && c.Tag == "coin")
{
if (player.Bounds.IntersectsWith(c.Bounds))
{
this.Controls.Remove(c);
score++;
}
}
}
lblScore.Text = "Score: " + score;
if (score == totalCoins)
{
gameOver();
MessageBox.Show("You Win!" + "\n" + "You reach the maximum score: " + score);
this.Close();
}
}
Game Over:
private void gameOver()
{
timer1.Stop();
lblGame.Visible = true;
lblGame.Text = "Game Over!";
}
} }
Basically, I want that the character don't move in that direction if he hits an obstacle.
Anyone can help me?
Thank you.
This is a different and hopefully simpler way to test for obstacle hit, I dont know if it can compile but i hope you get the general idea
First calculate x and y movement, then apply that movement to a copy of the players bounds and check if it intersects with any obstacle, if it does break out of the loop, if not test next obstacle
If no intersections found then move the player
Need to ensure that System.Drawing.Rectangle originalBounds = player.Bounds actually creates a copy of the players bounds, otherwise the player will move back and forward while the loop is running
private void timer1_Tick(object sender, EventArgs e)
{
int moveX = 0;
int moveY = 0;
bool hitObstacle = false;
System.Drawing.Rectangle originalBounds = player.Bounds; // make sure this is a copy of players bounds rectangle.
if(goLeft)
moveX = -playerSpeed;
else if(goRight)
moveX = playerSpeed;
else if (goUp)
moveY = -playerSpeed;
else if (goDown)
moveY = playerSpeed;
originalBounds.Offset(moveX,moveY);
foreach (Control x in this.Controls)
{
if (x is PictureBox && x.Tag == "obstacle") {
if (originalBounds.IntersectsWith(x.Bounds)) {
hitObstacle = true;
break;
}
}
if(hitObstacle==false) {
player.Bounds=originalBounds;
}
if (player.Left > 641)
.....

How do I move the Image inside the picturebox?

I want an Image to move inside the picturebox. It shouldn't be possible that you can drag it out. I found an answer with the Padding and tried it out but it drags in the opposite direction. So I tried out to switch it with Right and down, but it is not getting dragged. Also I found an answer where the picturebox get moved but then it can be moved out of the form and isn't there anymore. So I need something that can just move the picture inside the picturebox or something that moves the picturebox but not out of the form.
private bool Dragging;
private Point lastLocation;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Dragging = true;
lastLocation = e.Location;
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (Dragging == true)
{
int dx = e.X - lastLocation.X;
int dy = e.Y - lastLocation.Y;
pictureBox1.Padding = new Padding(0, 0, Padding.Right - dx, Padding.Bottom - dy);
pictureBox1.Invalidate();
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
Dragging = false;
}
Do this
pictureBox1.Padding = new Padding(Padding.Left + dx, Padding.Top + dy, Padding.Right - dx, Padding.Bottom - dy);
instead of this
pictureBox1.Padding = new Padding(0, 0, Padding.Right - dx, Padding.Bottom - dy);
I have done it by creating a panel and inserted image box inside of it.It's working in my side.Please find the code blow .
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
int moveLeftRight = e.X + pictureBox1.Left - MouseDownLocation.X;
int moveUpDown = e.Y + pictureBox1.Top - MouseDownLocation.Y;
int panlTopLocation = panel1.Location.Y;
int panlbottomLocation = panel1.Location.Y + panel1.Height - pictureBox1.Height;
int panlLeftLocation = panel1.Location.X;
int panlRightLocation = panel1.Location.X + panel1.Width - pictureBox1.Width ;
if (panlLeftLocation < moveLeftRight)
{
if (panlRightLocation > moveLeftRight)
{
pictureBox1.Left = moveLeftRight;
}
else
{
pictureBox1.Left = panlRightLocation;
}
}
else
{
pictureBox1.Left = panlLeftLocation;
}
if (panlTopLocation < moveUpDown)
{
if (panlbottomLocation > moveUpDown)
{
pictureBox1.Top = moveUpDown;
}
else
{
pictureBox1.Top = panlbottomLocation;
}
}
else
{
pictureBox1.Top = panlTopLocation;
}
}
}

Categories