Search code examples
c#screensaverbounce

How to keep moving PictureBox in boundaries C# Visual Studio 2010


I am writing a bouncing logo screensaver in Visual Studio 2010 using C#. I have never written in C# before today so I am apologizing for any ignorance in advanced. I am importing an image to the form using PictureBox. Is there a way to find the boundaries of the PictureBox so I can compare it to the boundaries of the screen (using screen.Bounds for screen boundaries)? Like I said, I've never programmed in C# before so I am not sure what other details you will need, if any. Please let me know and I'll put up whatever I can. Thank you.

EDIT: My bounce method is written in public partial class ScreensaverForm. The frame is in static class Program. My boundary check in the bounce method is if(picturebox.Bounds.Bottom == this.Bounds.Bottom). This seems to check for boundaries, but the boundaries are not the boundaries of the frame. How do I call the frame attributes?


Solution

  • Unless I'm missing something.

    Get the Screenbounds as a Rectangle.

    screenrectangle.Contains(new Rectangle(MyPictureBox.Location, MyPictureBox.Size))
    

    will give you true if it's all on screen.