Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / April 2008

Tip: Looking for answers? Try searching our database.

Detect scrollbars on treeview

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jesper, Denmark - 05 Apr 2008 16:41 GMT
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
Claes Bergefall - 07 Apr 2008 10:24 GMT
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

> Hi,
>
[quoted text clipped - 31 lines]
>        MsgBox "A vertical scroll bar is NOT visible."
>    End If

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.