471,354 Members | 1,729 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

Detect scrollbars on treeview

Hi,

Is there a way to detect whenever scrollbars (the vertical) are shown on a
treeview
I need to know.

1) If scrollbars are visible after a rezise
2) If scrollbars are visible after change in content (e.g. nodes
collapsed/expanded, nodes added/deleted ). Any event to hook into?

I found something to solve (1) in VB6.0 (see below) but dont know how to
translate this into .net.

Dim wndStyle As Long

' Retrieve the window style of the control.
wndStyle = GetWindowLong(TreeView1.hwnd, GWL_STYLE)

' Test if the horizontal scroll bar style is present
' in the window style, indicating that a horizontal
' scroll bar is visible.
If (wndStyle And WS_HSCROLL) <0 Then
MsgBox "A horizontal scroll bar is visible."
Else
MsgBox "A horizontal scroll bar is NOT visible."
End If

' Test if the vertical scroll bar style is present
' in the window style, indicating that a vertical
' scroll bar is visible.
If (wndStyle And WS_VSCROLL) <0 Then
MsgBox "A vertical scroll bar is visible."
Else
MsgBox "A vertical scroll bar is NOT visible."
End If
Apr 5 '08 #1
1 5950
Here's the VB code translated to C#. I don't think there is any event for
when the scrollbar becomes visible so you probably need to check manually
after anything that might cause a scrollbar to show up.

private const int GWL_STYLE = -16;
private const int WS_VSCROLL = 0x00200000;
private const int WS_HSCROLL = 0x00100000;

[DllImport("user32.dll", ExactSpelling = false, CharSet = CharSet.Auto)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);

....

int style = GetWindowLong(treeView1.Handle, GWL_STYLE);
bool hasHScroll = ((style & WS_HSCROLL) != 0);
bool hasVScroll = ((style & WS_VSCROLL) != 0);

/claes
"Jesper, Denmark" <Je***********@discussions.microsoft.comwrote in message
news:72**********************************@microsof t.com...
Hi,

Is there a way to detect whenever scrollbars (the vertical) are shown on a
treeview
I need to know.

1) If scrollbars are visible after a rezise
2) If scrollbars are visible after change in content (e.g. nodes
collapsed/expanded, nodes added/deleted ). Any event to hook into?

I found something to solve (1) in VB6.0 (see below) but dont know how to
translate this into .net.

Dim wndStyle As Long

' Retrieve the window style of the control.
wndStyle = GetWindowLong(TreeView1.hwnd, GWL_STYLE)

' Test if the horizontal scroll bar style is present
' in the window style, indicating that a horizontal
' scroll bar is visible.
If (wndStyle And WS_HSCROLL) <0 Then
MsgBox "A horizontal scroll bar is visible."
Else
MsgBox "A horizontal scroll bar is NOT visible."
End If

' Test if the vertical scroll bar style is present
' in the window style, indicating that a vertical
' scroll bar is visible.
If (wndStyle And WS_VSCROLL) <0 Then
MsgBox "A vertical scroll bar is visible."
Else
MsgBox "A vertical scroll bar is NOT visible."
End If

Apr 7 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

24 posts views Thread by Nobody | last post: by
6 posts views Thread by Etienne | last post: by
reply views Thread by SJ via .NET 247 | last post: by
5 posts views Thread by Bart Schelkens | last post: by
reply views Thread by Bart Schelkens | last post: by
17 posts views Thread by Dino M. Buljubasic | last post: by
reply views Thread by Sanjib Biswas | last post: by
1 post views Thread by Victor Rodriguez | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.