.NET Auto Scroll a Windows Control
.NET Auto Scroll a Windows Control
Author
Discussion

TheExcession

Original Poster:

11,669 posts

280 months

Tuesday 24th January 2006
quotequote all
I havea form with a third party windows spread sheet like control on it.

As I ad drows to the sheet control I'd like it to automatically scroll down keeping the new row in view.

In the past I've managed this by sending a Windows message to the control in question
e.g. sendMessage(win.WM_VSCROLL,win.SB_BOTTOM,200);

...but I can't find sight nor sound of any such thing in .NET...

Anybody got any idea how to do this to a .NET control (regardless of this one being a 3rd party jobbie)

Oh.. project is in VB as well

dilbert

7,741 posts

261 months

Tuesday 24th January 2006
quotequote all
Somewhere in there will be a WndProc... If you can get to that, and get a HWND for the control, then you need SBM_GETSCROLLINFO, and SBM_SETSCROLLINFO. Both functions take a SCROLLINFO struct pointer in lParam, and a BOOL in wParam that indicates redraw (set to true for set and false for get);

WIN32 SDK said:

The SCROLLINFO structure contains scroll bar parameters to be set by the SetScrollInfo function (or SBM_SETSCROLLINFO message), or retrieved by the GetScrollInfo function (or SBM_GETSCROLLINFO message).

typedef struct tagSCROLLINFO { // si
UINT cbSize;
UINT fMask;
int nMin;
int nMax;
UINT nPage;
int nPos;
int nTrackPos;
} SCROLLINFO;
typedef SCROLLINFO FAR *LPSCROLLINFO;

Members
cbSize
Specifies the size, in bytes, of this structure.
fMask
Specifies the scroll bar parameters to set or retrieve. This member can be a combination of the following values: Value Meaning
SIF_ALL Combination of SIF_PAGE, SIF_POS, SIF_RANGE, and SIF_TRACKPOS.
SIF_DISABLENOSCROLL This value is used only when setting a scroll bar's parameters. If the scroll bar's new parameters make the scroll bar unnecessary, disable the scroll bar instead of removing it.
SIF_PAGE The nPage member contains the page size for a proportional scroll bar.
SIF_POS The nPos member contains the scroll box position, which is not updated while the user drags the scroll box.
SIF_RANGE The nMin and nMax members contain the minimum and maximum values for the scrolling range.
SIF_TRACKPOS The nTrackPos member contains the current position of the scroll box while the user is dragging it.
nMin
Specifies the minimum scrolling position.
nMax
Specifies the maximum scrolling position.
nPage
Specifies the page size. A scroll bar uses this value to determine the appropriate size of the proportional scroll box.
nPos
Specifies the position of the scroll box.
nTrackPos
Specifies the immediate position of a scroll box that the user is dragging. An application can retrieve this value while processing the SB_THUMBTRACK notification message. An application cannot set the immediate scroll position; the SetScrollInfo function ignores this member.


But depending on what you're calling from you'll have to get the data alignment right. There may be other ways.


>> Edited by dilbert on Tuesday 24th January 13:56

TheExcession

Original Poster:

11,669 posts

280 months

Tuesday 24th January 2006
quotequote all
Hey,

yeah.. just found this:

Windows.Forms.Message.Create()

Which takes the control's handle and a few other message params... I just tried it but this control seems to be ignoring the message


(edited for appauling typing)


>> Edited by TheExcession on Tuesday 24th January 14:26

dilbert

7,741 posts

261 months

Tuesday 24th January 2006
quotequote all
TheExcession said:
Hey,

yeah.. just found this:

Windows.Forms.Message.Create()

Which takes the control's handle and a few other message params... I just tried it but this control seems to be ignoring the message


(edited for appauling typing)


>> Edited by TheExcession on Tuesday 24th January 14:26


An HWND, which your control must have, can implement a scrolling pane in three ways. I can't offer any advice whatever about getting these base handles from where you are, but if you can get them, it will work.

The three ways are;

1) Implement the main window, as a window, and then use windows scrollbars that have their own HWND's.
2) Implement the main window, as a window, but use the default property of all windows to present a scrolbar in the non-client area (frame) of the window.
3) As (1) but using a 3rd party scrollbar.

The description that I gave for control, works for 1 but only if you use the HWND of the actual scrollbar. If you use the message on the main window nothing happens.
If you have (2) then it should work, but you would need to use WM_HSCROLL & WM_VSCROLL.
If you have (3) then you may not be able to get it to work, unless you know what the third party interface does.

You can identify third party scrollbars, by their third party look and feel.
You can iterate child windows if you have an HWND by using the win32 function;

HWND GetWindow(HWND,UINT)




>> Edited by dilbert on Tuesday 24th January 15:27