Force a panel to scroll

R

Raymond Dynowski

How do you force a panel to scroll in code.
I have a large picture box inside my panel.
I would like the panel to default to the centre of the screen, rather than
the scrollbars showing the top left corner

Thanks
Ray
 
S

Shakir Hussain

Try this

private const int WM_VSCROLL = 0x115;
private const int SB_LINEDOWN = 1;
private const int SB_PAGEUP= 2;
private const int SB_PAGEDOWN= 3;
private const int SB_THUMBPOSITION= 4;
private const int SB_THUMBTRACK= 5;
private const int SB_TOP= 6;
private const int SB_BOTTOM = 7;
private const int SB_ENDSCROLL = 8;

[DllImport("user32.dll")]
private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam,
IntPtr lParam);

// use the constant values based on the functionality
SendMessage(panel1.Handle, WM_VSCROLL, (IntPtr) SB_LINEDOWN , IntPtr.Zero);
 
J

John Wood

I would like the panel to default to the centre of the screen, rather than
the scrollbars showing the top left corner
I'm not sure what you mean by this... you want to center the picture? Is the
picture larger than the panel in which it's contained?
 
J

Jay B. Harlow [MVP - Outlook]

Raymond,
How do you force a panel to scroll in code.
I have a large picture box inside my panel.
Have you tried setting the Panel.AutoScrollMinSize to the size of the
picture box, so the scroll bars appear, then set the
Panel.AutoScrollPosition so the PictureBox is "centered".

Be certain to read the help on AutoScrollPosition as the coordinates you
give it to scroll may not be what you initially expect (you need to use
negative offsets sometimes).
I would like the panel to default to the centre of the screen, rather than
the scrollbars showing the top left corner
Do you want the image to center the panel, or do you really want the panel
to center the screen?

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top