Hi Benny and Manu,
I wrote this class to add the scroll event and 2 getters to have the
horizontal and vertical position of the scrollbars.
Assume your Treeview is named myTreeView ( TreeViewScroll myTreeView) :
To get the horizontal position, use myTreeView.HScrollPos (be careful of
the unit. I think it's in pixels)
To get the vertical position use myTreeView.VScrollPos (be careful of the
unit. I think it's in lines)
To add a listener for the scrollbars use myTreeView.Scroll+=new
ScrollEventHandler(myTreeView_Scroll);
This event is almost the same as the usual scroll event for a control. The
only difference is that the newValue is not set when event like
small(de)increment or large(de)increment occurs. If you want so, use the
getters and the scrolltype to determine the newValue or calculate it in the
WndProc. For events like thumbposition or thumbtrack, everything is
correctly filled.
Here is the source code :
using System;
using System.Windows.Forms;
public class TreeViewScroll:TreeView {
private const int SB_HORZ=0;
private const int SB_VERT=1;
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int GetScrollPos(int hWnd,int nBar);
public int HScrollPos {
get {return GetScrollPos((int)Handle,SB_VERT);}
}
public int VScrollPos {
get {return GetScrollPos((int)Handle,SB_HORZ);}
}
public event ScrollEventHandler Scroll;
protected override void WndProc(ref Message m) {
if (Scroll!=null) {
switch(m.Msg) {
case KERMLSoftware.Helpers.Win32.WinMsg.WM_VSCROLL: {
ScrollEventType
t=(ScrollEventType)Enum.Parse(typeof(ScrollEventType),
(m.WParam.ToInt32()&65535).ToString());
Scroll(m.HWnd,new
ScrollEventArgs(t,((int)(m.WParam.ToInt64()>>16))&255));
} break;
}
}
base.WndProc (ref m);
}
}
Hope it helps,
Ludovic SOEUR.
Manu said:
Hi Benny
I have the same problem that u faced. And I see that there are no replies
with solutions. If you have found the solution please let me know how to go
about it.
Thanks and Regards,
Manu