By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,528 Members | 944 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,528 IT Pros & Developers. It's quick & easy.

Scroll bars in treeview - how can you get onscroll as well as theirposition?

P: n/a
I've looked around msdn for about an hour now and can't figure out how
to place an event when the user scrolls, or even how to get the value of
where the scroll bar is actually placed...

Anyone know how to use this event, or how to get the scroll bar info?

~Benny
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a
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

"Benny Raymond" wrote:
I've looked around msdn for about an hour now and can't figure out how
to place an event when the user scrolls, or even how to get the value of
where the scroll bar is actually placed...

Anyone know how to use this event, or how to get the scroll bar info?

~Benny

Nov 16 '05 #2

P: n/a
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.d ll")]
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(ScrollEventTy pe),
(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" <Ma**@discussions.microsoft.com> a écrit dans le message de
news:34**********************************@microsof t.com...
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

"Benny Raymond" wrote:
I've looked around msdn for about an hour now and can't figure out how
to place an event when the user scrolls, or even how to get the value of
where the scroll bar is actually placed...

Anyone know how to use this event, or how to get the scroll bar info?

~Benny

Nov 16 '05 #3

P: n/a
I have forgotten to replace all my strings. Instead of
case KERMLSoftware.Helpers.Win32.WinMsg.WM_VSCROLL : {,
use case WM_VSCROLL:case WM_HSCROLL: {
with theses consts :
private const int WM_VSCROLL=0x0115
private const int WM_HSCROLL=0x0114;

Sorry for the mistake.

Hope it helps,

Ludovic SOEUR.

"Ludovic SOEUR" <Lu***********@hotmail.com> a écrit dans le message de
news:Ou**************@TK2MSFTNGP10.phx.gbl...
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.d ll")]
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(ScrollEventTy pe),
(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" <Ma**@discussions.microsoft.com> a écrit dans le message de
news:34**********************************@microsof t.com...
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

"Benny Raymond" wrote:
I've looked around msdn for about an hour now and can't figure out how
to place an event when the user scrolls, or even how to get the value of where the scroll bar is actually placed...

Anyone know how to use this event, or how to get the scroll bar info?

~Benny


Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.