davidhov

I want to use a Panel control as a "window" onto a larger (real, fixed) area containing the child controls. Currently, the AutoScroll mechanism accomplishes this by moving everything around in a "virtual canvas". I want to avoid the movement and adjust painting in the Panel window by the AutoScrollOffset.

In other words, I want "real" scrolling by maintaining a large bitmap area for the Panel's controls surface and use the Panel's display area as a "viewport" to display a section of that area based on the scroll position.

Is this possible Is there a way to retarget the Paint operations for all the Panel's Controls so as to honor an offset Can I create a larger, permanent Bitmap for the Panel's surface


Re: Windows Forms General Scrolling larger "canvas"

Alan Robbins

David

The panel control works really well for it's intended purpose -- That being said every time I have been faced with this kind of problem I have ended up by replacing the panel with a picture box and two scroll bars, and performing all the drawing and layout operations myself because:

  1. The panel's "design surface" has a fixed size limit.
  2. The panel will scroll to put the focus control into view when focus changes, this is difficult to control.
  3. If you load up a panel with lots and lots of controls it starts sucking up a lot of resources.

A double buffered, owner drawn control is alternative. This gives you 100% control over every aspect of the drawing and scrolling. You can float an input control (text box, check box, etc.) on "top"... Once you go this route you'll find you can redraw the entire viewport much much faster than an out of the box panel control can, and you can fine tune the scrolling to whatever you want it to be.






Re: Windows Forms General Scrolling larger "canvas"

nobugz

Check this thread for code.





Re: Windows Forms General Scrolling larger "canvas"

davidhov

Thanks; my experiences bear out your statements. However, I wanted to keep most of the good things that the Panel control and standard containers provide, like clipping.

I just discovered that if my panel implements the IContainerControl interface (e.g., public class GPanel : System.Windows.Forms.Panel, IContainerControl), then my contained controls are selected correctly and I can suppress the invocation of ScrollControlIntoView! This makes everything better. Before, I was using OnEnter/OnLeave events, and scrolling interfered badly-- the OnLeave event never happened after a scroll operation. I need consistent UI cues, and now I can have them.