Search code examples
c#gdi+scrolldrawingonpaint

GDI+ Problem encountered in drawing multiples rectangles on the form


I whant to draw a table in C# Windows Forms using GDI+. When the number of rectangles is too large for all rectangles to be displayed on the form, it does not scroll. And can not access those who did not fit the form.

What I need to do to see everything I drawing on the form?

Thanks.


Solution

  • Use a Panel or UserControl for drawing, make it large enough that your complete table fits and then let the form auto-scroll.

    A component doesn't care about what you draw on it or where. Scrollbars do not magically appear just because you're drawing something in a place where it can't be seen. So either use a component lage enough that your drawing fits (you should know how large it gets) and let the container scroll. Or use scrollbars directly and translate your drawing accordingly. The latter option is more complicated, though :)