Yes, the solution is pretty basic, as long as the size you want to draw won't go over 32k pixels width:
- Put your
Panel
inside another one.
- The outer
Panel
has AutoScroll=true
- The inner one where you draw has the size of your drawing.
- You need to draw in the
Paint
event, as you should anyway (!)
Now the outer Panel
shows a horizontal scrollbar and the user can scroll right and left and see all parts of the drawing..
One alternative would be to add a dummy control that enforces the AutoScroll
of your drawing Panel
to work, but I find using two Panels
the cleaner way to go..
Note: You should either use a PictureBox
or at least a double-buffered Panel
subclass to avoid flicker and tearing:
class DrawPanel : Panel
{
public DrawPanel()
{ DoubleBuffered = true; }
}
Update: Instead of a Panel
, which is a Container
control and not really meant to draw onto you can use a Picturebox
or a Label
(with Autosize=false
); both have the DoubleBuffered
property turned on out of the box and support drawing better than Panels
do.