【问题标题】:How to do vertical and horizontal scrolling in treeview?如何在树视图中进行垂直和水平滚动?
【发布时间】:2011-06-06 14:54:45
【问题描述】:

我有一个固定大小的树视图。我怎样才能让它滚动到水平和垂直?当我将 Scrollable 设置为 true 时,它​​只添加垂直滚动,当滚动到达表单底部并且剩余文本时,滚动没有下降。请帮帮我。

p.s 抱歉英语不好

【问题讨论】:

  • 你的意思是不能一直滚动到最后一个treeview node?您是动态添加项目吗?
  • 是的,如果三视图中有很多节点,那么我无法到达最后一个。不,我不添加动态,我将数据库名称和表名称从 sql 加载到树视图。
  • 有点小技巧,但看看它是否有效。添加节点后,添加:myTreeView.Nodes.Item[myTreeView.Nodes.Count - 1].EnsureVisible()
  • Item有错误,节点中没有Item

标签: c# winforms treeview scroll


【解决方案1】:

你可以试试这个方法

private const int WM_SCROLL = 276; // Horizontal scroll
private const int WM_VSCROLL = 277; // Vertical scroll
private const int SB_LINEUP = 0; // Scrolls one line up
private const int SB_LINELEFT = 0;// Scrolls one cell left
private const int SB_LINEDOWN = 1; // Scrolls one line down
private const int SB_LINERIGHT = 1;// Scrolls one cell right
private const int SB_PAGEUP = 2; // Scrolls one page up
private const int SB_PAGELEFT = 2;// Scrolls one page left
private const int SB_PAGEDOWN = 3; // Scrolls one page down
private const int SB_PAGERIGTH = 3; // Scrolls one page right
private const int SB_PAGETOP = 6; // Scrolls to the upper left
private const int SB_LEFT = 6; // Scrolls to the left
private const int SB_PAGEBOTTOM = 7; // Scrolls to the upper right
private const int SB_RIGHT = 7; // Scrolls to the right
private const int SB_ENDSCROLL = 8; // Ends scroll

[DllImport("user32.dll",CharSet=CharSet.Auto)]
private static extern int SendMessage(IntPtr hWnd, int wMsg,IntPtr wParam, IntPtr lParam);

SendMessage(treeView.Handle, WM Scroll Message, (IntPtr) Scroll Command ,IntPtr.Zero);

向上滚动页面

SendMessage(treeView.Handle, WM_VSCROLL,(IntPtr)SB_PAGEUP,IntPtr.Zero);

向下滚动页面

 SendMessage(treeView.Handle, WM_VSCROLL,(IntPtr)SB_PAGEDOWN,IntPtr.Zero);

【讨论】:

    【解决方案2】:

    最终对我有用的是修复 [keyboardP] 的代码 sn-p:

    myTreeView.Nodes[myTreeView.Nodes.Count - 1].EnsureVisible();
    

    转眼间。水平条。

    【讨论】:

      猜你喜欢
      • 2015-08-04
      • 2017-01-01
      • 2015-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-03
      相关资源
      最近更新 更多