Drawing in a Panel

Hi,

I need to do complex drawing in a Panel to give the opportunities to the user to see the design prior to print it. I put really basic code to draw a rectangle in the panel but I don't have any scroll bar to see the rest of it.

How do we tell to the panel that it's fixed display area will be ex: 900x400 and the virtual display area 3000x2000.

I tried to set the autoscroll prop but without success

Code sample (very basic...I know Smile)

Dim vdesign As System.Drawing.Graphics

vdesign = Panel1.CreateGraphics()

vdesign.DrawRectangle(System.Drawing.Pens.Black, New System.Drawing.Rectangle(0, 0, 3000, 200))

Thanks

Serge


Answer this question

Drawing in a Panel

  • Robert Neal


    I wasn't wrong... you just provided an alternative, but like you said, you will have to manage more yourself then.


  • Jnnet

    I believe when it comes to drawing on a panel.. you gotta do the math.  :) 

    It depends on the performance requirements, but if really necessary, you can create an image object of whatever size, and resize that according to your panel's size specifications.

  • paulfl

    Few things about this approach:

    Enabling AutoScroll means that scrollbars will appear as soon as the child controls go out of visible range. In your case you don't have any child controls, you're painting directly to the control. You could fix this by embedding a child control with the sizes that you mentioned and paint on that control. This could also be a panel if you want.

    Still, you have to keep in mind that having controls of this size should get some alarm bells ringing. In cases where my client areas get really big, I tend to manage the virtual plane myself and handle the painting and scrolling myself. This is especially obligatory when the size gets *really* big, since the panel size is limited to 16 bit values (cannot exceed 32767 pixels in both x and y).

    Lastly, I don't know a lot about VB, but you don't need to call CreateGraphics... you can simply just override the OnPaint method, or respond to the Paint message in order to obtain a Graphics object.

    Hope this helps.

    Regards,
    Jelle



  • larryfran

     jvanderbeek wrote:

    Enabling AutoScroll means that scrollbars will appear as soon as the child controls go out of visible range.



    Wrong. Set AutoScrollMinSize to the extent of what you are drawing on the Panel to make scrollbars appear automatically when the client area gets smaller than AutoScrollMinSize of your panel. In your case set the AutoScrollMinSize to a Size of 3000 x 2000 pixels. Don't forget to offset all your painting with the current scrollbar values.



  • Arnie_Mac

    Thanks, I'll give it a shot.

    The reason we want to do this, we have to create a huge Gant Chart that we tried to do in Crystal Report without success. It seems that it can't handle huge page size.

    It must be printed on a "Plotter printer".

  • Drawing in a Panel