drawing rectangles on a panel

I am drawing several rectangles on a panel, and I am exceeding the viewable size of the panel. I am trying to get the panel to scroll after my rectangles exceed the area. How can I do this? I guess the autoscroll only works with controls being added.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

When it comes to scrolling a Panel, think of it like looking through a window at a much larger surface, very close to the window, but too large all to be seen at once, so you have to move the rear surface around to see different aspects if AutoScroll is enabled.

It is on that rear area where the controls that are contained by a panel exist, and in this context, the outer range of the furthers controls specifies the maximum size of the back surface. If all of the controls are within the rage of the window, then there is no need for scrolling and AutoScroll is ignored.

Here comes the problem for what you are looking to do... you want to paint something onto that back surface, and have it be scrollable just like the rest of what is back there. The problem is... you can’t paint to it, only place controls there. Any painting you to do the Panel actually occurs on the window to the back area.

One way around this... would be to place a PictureBox inside of the panel and draw to it. By doing it this way... you are able to control the size of your viewing window to your drawing... and have a wide open surface to draw to, and something that is more conducive to such a use.
fizchAuthor Commented:
Will I have to create a new picture box for everything I draw? If I only use one picture box, won't I have to create a large one and then have the panel scrolling all the time (even when there hasn't been anything drawn)?
There are a couple of ways you could do this… if your rectangles are simple... you could always build a Control that does such drawing itself... and which could easily just be dropped into the Panel without the need for the giant PictureBox.

One way to get around the potential issue of having a PictureBox that is far larger than needed, is to make its size a little more dynamic by basing it off of some math you would do (if possible) prior to your drawing.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fizchAuthor Commented:
That worked. I added all of my rectangles to the picturebox and resized it everytime.

Thanks for your help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.