如何检测Treeview的滚动方向 [英] How to detect the scroll orientation of a Treeview

查看:71
本文介绍了如何检测Treeview的滚动方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以创建一个表单,并如下检测其滚动状态:

I can create a form, and detect its scroll status as follows :

Form TheForm = new Form();
TheForm.AutoScroll = True;
...

If(TheForm.VerticalScroll.Visible)
{
   // any action ...
}



但是,尽管我可以将treeview设置为可滚动,如下所示:
(对于TreeView的"scrollable"属性,似乎默认为true)



However, though I can set a treeview be scrollable as follows :
(it seems be default true for ''scrollable'' attribute of TreeView)

TreeView TheTreeview = new TreeView();
TheTreeView.Scrollable = True;

...

我无法通过以下行检测到TheTreeview的滚动状态:

...

I can not detect the scroll status of TheTreeview with following line :

If(TheTreeview.VerticalScroll.Visible)
{
    // action ...
}

由于TreeView似乎没有"VerticalScroll"属性,
有人可以帮我看看如何检测TreeView的滚动状态吗?
非常感谢!

Since there seems be no ''VerticalScroll'' attribute for TreeView,
can anybody help to show me how to detect the scroll status of a TreeView ?
Thanks so much !

推荐答案

您将需要使用user32 API的GetWindowLong函数执行一些PInvoke任务.这样的东西

You are going to need to do some PInvoke stuff with GetWindowLong function of the user32 API. Something like this

const int GWL_STYLE = (-16);
       const long WS_HSCROLL = 0x00100000L;
       const long WS_VSCROLL = 0x00200000L;

       [DllImport("user32.dll")]
       public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
       private void CheckForScrollBars()
       {
           long windowStyle;
           //get styles for treeview(named treeView1 for originality).
           windowStyle = GetWindowLong(treeView1.Handle, GWL_STYLE);
           //test if Horizontal ScrollBar is visible
           if ((windowStyle & WS_HSCROLL) == 0)
           {
               MessageBox.Show("A horizontal scroll bar is visible.");
           }
           else
           {
               MessageBox.Show("A horizontal scroll bar is NOT visible.");
           }
           //Test if the vertical scrollbar is visible
           if ((windowStyle & WS_VSCROLL) == 0)
           {
               MessageBox.Show("A vertical scroll bar is visible.");
           }
           else
           {
               MessageBox.Show("A vertical scroll bar is NOT visible.");
           }
       }



希望对您有帮助



Hope this helps


这篇关于如何检测Treeview的滚动方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆