Detect scrollbars on treeview

  • Thread starter Jesper, Denmark
  • Start date
J

Jesper, Denmark

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
 
C

Claes Bergefall

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
 

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