On the form there is a panel element in which I move the picture ( picturebox ):

 //перемещаемся в право pictureBox1.Left += 50; //перемещаемся в низ pictureBox1.Top += 50; 

Those. moves in all directions by 50. Tell me how to make the picture not go beyond the bounds of the panel element?

    1 answer 1

    A wonderful site .

     if (pictureBox1.Right >= panel1.ClientSize.Width) { /* перешли за правую границу */ } if (pictureBox1.Bottom >= panel1.ClientSize.Height) { /* перешли за нижнюю границу */ } if (pictureBox1.Left <= 0) { /* перешли за левую границу */ } if (pictureBox1.Top <= 0) { /* перешли за верхнюю границу */ }