How to programmatically scroll a panel?

O

Open Wound

What method can I call to programmatically scroll a panel?

There is ScrollControlIntoView() but I don't have a control to scroll
into view. I just want the panel to scroll up by 100 pixels.

Setting AutoScrollPosition doesn't seem to work either. The values I
set are not honored, and are apparently modified by the framework.

By the way, what I am trying to implement is the behavior seen in
Notepad (and other Windows apps) where you hold the mouse button down
and drag the mouse below the window, and the contents keep scrolling
up while the mouse button is held down. I am using a timer to achieve
this. In the timer event handler, I want to programmatically scroll
the panel up.
 
N

Nicholas Paldino [.NET/C# MVP]

Open Wound,

You could try sending the WM_VSCROLL message to the window (assuming the
scrollbars are standard scrollbars) by calling the SendMessage API function
through the P/Invoke layer.

Additionally, you could always set the DisplayRectangle propery,
shifting the view on the control by 100 pixels, like so:

// The panel is mobjPanel.
mobjPanel.DisplayRectangle = mobjPanel.DisplayRectangle.Offset(0, 100);

Hope this helps.
 
C

cody

You cannot assign DisplayRectangle because it is readonly.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk

Nicholas Paldino said:
Open Wound,

You could try sending the WM_VSCROLL message to the window (assuming the
scrollbars are standard scrollbars) by calling the SendMessage API function
through the P/Invoke layer.

Additionally, you could always set the DisplayRectangle propery,
shifting the view on the control by 100 pixels, like so:

// The panel is mobjPanel.
mobjPanel.DisplayRectangle = mobjPanel.DisplayRectangle.Offset(0, 100);

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Open Wound said:
What method can I call to programmatically scroll a panel?

There is ScrollControlIntoView() but I don't have a control to scroll
into view. I just want the panel to scroll up by 100 pixels.

Setting AutoScrollPosition doesn't seem to work either. The values I
set are not honored, and are apparently modified by the framework.

By the way, what I am trying to implement is the behavior seen in
Notepad (and other Windows apps) where you hold the mouse button down
and drag the mouse below the window, and the contents keep scrolling
up while the mouse button is held down. I am using a timer to achieve
this. In the timer event handler, I want to programmatically scroll
the panel up.
 
J

Joey Johnson

I got the same error too. Also new to C#, "calling the SendMessage API
function through the P/Invoke layer" translates to "use floober via blavar
to get proobser"... please post code example for us newbies so we know what
this means!


In the meantime, I found that this will scroll a panel too:

myPanel.AutoScrollPosition = new Point(0,1152);

Change Point(0,y) so that y is how far you want to scroll up in panel.

-Joey
 
C

cody

I got the same error too. Also new to C#, "calling the SendMessage API
function through the P/Invoke layer" translates to "use floober via blavar
to get proobser"... please post code example for us newbies so we know what
this means!

This means nothing else thatn calling native code which resides in a dll
from a c# app:

since c# lacks header files you declare the function like that:

[DllImport("gdi32")]
public static extern IntPtr SelectObject(
IntPtr hdc, // handle to DC
IntPtr hgdiobj // handle to object
);

and then simply call it like you would call any other method.
In the meantime, I found that this will scroll a panel too:

myPanel.AutoScrollPosition = new Point(0,1152);

Change Point(0,y) so that y is how far you want to scroll up in panel.


Thats exactly how I solved my problem too!
 

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